Python Forum
sysv_ipc shared memory performance
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
sysv_ipc shared memory performance
#2
(Apr-04-2019, 12:47 PM)comotai Wrote: What is wrong with my code? Why is the performance so slow compared to C doing exactly the same thing?

If we are talking about CPython (standard Python), implementation of Python programming language in C,
execution model of a python program (script) is significantly differed from that is being written in C language. C-program is compiled into machine code and than executed. Python program is compiled into bytecode that is further interpreted/executed by CPython engine. That is why Python program is executed slower than C one. Sometimes one might use a just-in-time (JIT) compiler that compiles bytecode into machine code and runs it (e.g. PyPy). This usually leads to increasing of execution speed. In you case, you are likely never achieve comparable to C-language execution speed using CPython (or ever PyPy, Cython, or something else). You program is already written in C, and probably optimized. If you ever used Cython, that translates Python program into C-code, that is further compiled into executable, the program wouldn't be so fast, as it would natively written in C. The only way of improving performance in your case (if program isn't too complex) is to rewrite it using assembly language (or may be apply some optimization keys at compilation time, -O2 etc.). So, why do you need to rewrite a program (originally written in C) in Python?!

You can try to achieve comparable to C (but liekly slower, than you already have, I think) performance using NumPy package.

import numpy as np
data = memoryview(b'byte')  # point to your shared memory instead... 
result = np.ndarray(buffer=data, shape=(2,), dtype=np.int16) # change shape and dtype to interpret shared memory as array properly
# result is data interpreted as two 2-byte integers
Reply


Messages In This Thread
sysv_ipc shared memory performance - by comotai - Apr-04-2019, 12:47 PM
RE: sysv_ipc shared memory performance - by scidam - Apr-08-2019, 02:27 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Shared reference of variables... Denial 1 1,432 Aug-29-2020, 01:52 PM
Last Post: snippsat
  How to install and use a shared libary, via a .dll? ninjaisfast 0 1,303 Jul-09-2020, 03:23 PM
Last Post: ninjaisfast
  Performance enhancement fimmu 0 1,630 Feb-12-2020, 02:42 PM
Last Post: fimmu
  performance kerzol81 1 1,918 Oct-07-2019, 10:19 AM
Last Post: buran
  How I can do performance testing on my API a21250450 0 1,403 Jul-18-2019, 09:29 AM
Last Post: a21250450
  Python performance rvkstudent 4 3,003 Apr-25-2019, 09:29 AM
Last Post: rvkstudent
  Divisors shared the second numbers mircea_dragu 1 2,055 Feb-07-2019, 10:09 PM
Last Post: ichabod801
  running just one process shared among uses Skaperen 3 2,999 Aug-07-2018, 12:12 AM
Last Post: Skaperen
  Shared reference and equality zyo 3 3,177 Jun-30-2018, 07:10 PM
Last Post: ljmetzger
  Shared queues l00p1n6 3 3,001 May-15-2018, 01:38 PM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020