[Tutor] Cython question
Alan Gauld
alan.gauld at btinternet.com
Sat Jul 2 15:28:14 CEST 2011
"Albert-Jan Roskam" <fomcl at yahoo.com> wrote
> I used cProfile to find the bottlenecks, the two
> Python functions getValueChar and getValueNum.
> These two Python functions simply call two equivalent
> C functions in a .dll (using ctypes).
In that case cythin will speed up the calling loops
but it can't do anything to speed up the DLL calls,
you have effectively already optimised those
functions by calling the DLL.
> The problem is that these functions are called
> as many times as there are VALUES in a file
It might be worth a try if you have very big data sets
because a C loop is faster than a Python loop.
But don't expect order of magnitude improvements.
> So if I understand you correctly, this is not Cpu
> bound and, therefore, alas, Cython won't improve
> the excution time. Correct?
It may still be CPU bound in that the CPU is doing
all the work, but if the CPU time is in the DLL
functions rather than in the loop cython won't
help much.
CPU bound refers to the type of processing - is
it lots of logic, math, control flows etc? Or is
it I/O bound - reading network, disk, or user input?
Or it might be memory bound - creating lots of
in memory objects (especially if that results in
paging to disk, when it becomes I/O bound too!)
Knowing what is causing the bottleneck will
determine how to improve things. Use tools like
TaskManager in Windows or top in *nix to see
where the time is going and what resources are
being consumed. Fast code is not always the
answer.
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
More information about the Tutor
mailing list