Google apps
Main menu

Post a Comment On: Only Python

"Profiling adventures and cython - Introducing cython"

4 Comments -

1 – 4 of 4
Anonymous Anonymous said...

You should likely use

cdef double complex z

instead of

cdef complex z

The former makes z a low-level "unboxed" number (fast), whereas the latter AFAIK makes it a Python complex object (much slower since all arithmetic goes through the PyNumber API).

3:12 PM

Blogger André Roberge said...

Anonymous: thanks for the suggestion. I did that (and the same for the variable "c"). In addition, I had to replace z**2 by z*z for this to work, as I got an error message about "complex powers not yet supported".

Simply replacing z**2 by z*z brought down the time from 38 to 29 seconds (approximately); adding the "double" type declaration brought down the time to 22 seconds: nice, but not as much as can be obtained by working with real numbers only.

3:27 PM

Anonymous Anonymous said...

Now that's a surprise. Examining the assembler output, it seems that gcc does not inline complex multiplication, which apparently gives a factor of 10 difference.

With `-ffast-math` flag there is no performance difference (of plain C) double vs. complex routines.

6:46 PM

Anonymous patfla said...

The program wasn't actually drawing anything until I noticed that all instances on this page of

#self.canvas.create_line(x, y, x+1, y, fill="black")

are commented out.

I might also point out that, as best I can tell, the posts don't include actual instructions to build (or profile) with cython. I figured out how to do so of course looking elsewhere on the web. E.g.

Building Cython code

Other than that the exercise has been very helpful.

Je vous remercie - Patrick

3:25 PM

Spammers: none shall pass.
You can use some HTML tags, such as <b>, <i>, <a>

Comments on this blog are restricted to team members.

You will be asked to sign in after submitting your comment.
Please prove you're not a robot