I am compiling some cython extensions in linux and noticed that it defaults to using -O2 when building from the distutils mechanism. I was wondering if there was a simple way to change that to a -O3.
I have tried using the extra_compile_args on Extension objects, but that leads to both -O2 and -O3 being passed as arguments to gcc. I kind of want to play with other esoteric gcc options and thus am hoping I can just control the compilation step. An obvious question is "why don't I just run cython my.pyx and compile the results manually?". I would love to, is my answer... but the cython executable in /usr/local/bin/ throws a DistributionNotFound: Cython==0.12.1 error when run from the command line. I haven't quite figured that one out.
Anyway, I am not sure if its a cython thing, a distutils thing or a broken apt package thing. I simply grabbed cython out of the ubuntu 11.10 apt repo (and am currently using ubuntu 11.10).
Cython source file names consist of the name of the module followed by a . pyx extension, for example a module called primes would have a source file named primes. pyx . Cython code, unlike Python, must be compiled.
The Cython language is a superset of Python that compiles to C, yielding performance boosts that can range from a few percent to several orders of magnitude, depending on the task at hand. For work that is bound by Python's native object types, the speedups won't be large.
Using extra_compile_args=["-O3"]
in your setup.py, the "-O3"
should appear after the "-O2"
option overrading it. Check the share object (.so, or .dll) size in order to confirm it quickly.
Davide
larsmans comment was right - using /usr/bin/cython addresses my issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With