> Note that this uses a C long, which is size bound (as opposed to a Python
> long). Depending on your data, you might need more than that, e.g. a "long
> long" (although that's not 100% portable).

In fact, an int is probably ok, I used a long to be on the safe side.

>>     for i in range(len(new_pixels)):
>>         spam += abs(original_pixels[i] - new_pixels[i])
>>
>>     return 1020 * len((original_pixels)) - spam
>
> Regarding this bit, try running Cython with the "--annotate" option. This
> will generate an HTML file from your code that shows where things are
> running in Python code (yellow) rather than C code (try a mouse click). 80
> times faster sounds so slowish that there must still be type conversions
> involved. For example, have you imported "abs" from stdlib.h instead of
> using the Python builtin?

I already changed the len for the size. And yes, I was using the
python abs function. I imported the C one now. Now only the def line
and the return line are using Python (which is okay since the function
is called from Python).

Switching for the C abs is now 20 times faster than before. So roughly
a 1600 times improvement over pure Python.

Thanks!
>
> Stefan
> _______________________________________________
> Cython-dev mailing list
> [email protected]
> http://codespeak.net/mailman/listinfo/cython-dev
>
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to