Creating a PYD file

R

Rony

Is a PYD file created from Pyrex faster in execution then a PYD file
created from python source ?

Tia

Rony
 
T

Thomas Jollans

Is a PYD file created from Pyrex faster in execution then a PYD file
created from python source ?

How do you plan to create an extension module (*.so, *.pyd on Windows) from
Python source then?
 
R

Rony

Sorry that was a typo...
The question actually is, is a PYD file created from C faster then a
PYD file from Pyrex ?
I know it will depend on how it is written, but let's imagine a tiny
example, like

(Pseudo code)

result = arg1 + arg2
return result



Tia

Rony
 
T

Terry Reedy

is a PYD file created from C faster then a PYD file from Pyrex ?

Since a .pyd file from Pyrex is also from C, the question is ill-posed.
It is equivalent to "Does the C code generated by Pyrex compile to
faster or slower machine code than the C code generated by some other
person or program?". Leaving compiler variations aside, the answer
depend on the proficiency of the other source in relation to the
particular function being computed. Perhaps you already answered this...
I know it will depend on how it is written,

depending on what you meant by 'it'. To be fair, the two code have to
have exactly the same input/output relationships, including exception
raising.
 
M

Martin v. Loewis

(Pseudo code)
result = arg1 + arg2
return result

For this code, the manually-written version will most likely
be faster than the Pyrex-generated one.

This is, most likely, because the manually-written version will
assume a specific data type for the arguments (e.g. int), which
Pyrex will not.

As a consequence, the manually-written version will be more
restricted than the Pyrex one, and most likely, that will be
acceptable in your application.

Theoretically speaking.

Regards,
Martin
 
P

Philipp Pagel

Rony said:
Is a PYD file created from Pyrex faster in execution then a PYD file
created from python source ?

What do you mean? An African or European swallow?

Of course it depends on your choice of algorithm, programmer ability.familarity
with the respective langugage, ...

cu
Philipp
 
S

Stefan Behnel

Thomas Jollans, 19.08.2010 20:47:
How do you plan to create an extension module (*.so, *.pyd on Windows) from
Python source then?

You can try to compile it using Cython.

Stefan
 
S

Stefan Behnel

Rony, 19.08.2010 21:41:
The question actually is, is a PYD file created from C faster then a
PYD file from Pyrex ?

Most likely, yes.

However, when comparing to Cython instead of Pyrex, the answer really
depends on your code. Cython cannot be faster than the equivalent C code,
simply because it generates C code. However, if the Python call overhead
matters (e.g. in thin wrappers around simple C functions), Cython easily
wins because it uses various tweaks that you simply wouldn't write in your
own C code. If the overhead can be ignored, hand tuned C code wins often
but not always, with the obvious drawback of being much harder to write and
much longer in lines of code.

Generally speaking, if you can avoid it, don't write the extension in C.
You'll have your Cython code hand optimised long before your C code is even
close to running. And in the long run, the maintenance cost will always be
the dominating factor anyway.

Stefan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,122
Latest member
VinayKumarNevatia_
Top