Take the 2-minute tour ×

I wrote a python script to do some experiment with the Mandelbrot set. I used a simple function to find Mandelbrot set points. I was wondering how much efficiency I can achieve by calling a simple C function to do this part of my code? Please consider that this function should call many times from Python.

What is the effect of run time? And maybe other factors that should I aware?

share|improve this question
"Please consider that this function should call many times from Python." Generally this is a bad idea; it would be faster to call once from Python into native code and do as much work in the native code as you possibly can. The boundary between the two is not cheap. –  cdhowie Nov 9 '12 at 16:15
As a rule the way to improve performance is to measure what is slow and then optimise it, if you find your python code which you suspect is slow, and measure it, then compare with a C version then you will find the answer. This doesn't feel like an answer to your question, but I think what is much more important here is that if you were approaching optimisation correctly you wouldn't have to ask this question. :) –  jheriko Nov 9 '12 at 16:19
add comment

closed as not a real question by Martijn Pieters, jdi, Lev Levitsky, Jaguar, Matti Lyra Nov 9 '12 at 17:09


1 Answer

You'll want the python calls to your C function to be as little as possible. If you can call the C function once from python and get it to do most/all of the work, that would be better.

share|improve this answer
That is a ridiculously stupid article, illustrating poorly constructed benchmarks. Read the comments on it. But I agree with your actual answer. You should remove the article link though. –  jdi Nov 9 '12 at 16:36
Yes, I agree the benchmarks are poorly constructed and you cannot decide anything by looking at the results. –  Amir Masoud Nov 9 '12 at 16:41
add comment
