[Numpy-discussion] python numpy code many times slower than c++

Robert Kern robert.kern at gmail.com
Thu Jan 22 18:03:35 EST 2009


On Thu, Jan 22, 2009 at 17:00, Wes McKinney <wesmckinn at gmail.com> wrote:
> import cProfile
>
> def f():
>     pass
>
> def g():
>     for i in xrange(1000000):
>         f()
>
> cProfile.run("g()")
>
>>test.py
>          1000003 function calls in 1.225 CPU seconds
>
>    Ordered by: standard name
>
>    ncalls  tottime  percall  cumtime  percall filename:lineno(function)
>         1    0.000    0.000    1.225    1.225 <string>:1(<module>)
>   1000000    0.464    0.000    0.464    0.000 test.py:3(f)
>         1    0.761    0.761    1.225    1.225 test.py:6(g)
>         1    0.000    0.000    0.000    0.000 {method 'disable' of
> '_lsprof.Profiler' objects}
>
> Running this with line_profiler:
>
> Timer unit: 2.9485e-010 s
>
> File: test.py
> Function: g at line 9
> Total time: 0.855075 s
>
> Line #      Hits         Time  Per Hit   % Time  Line Contents
> ==============================================================
>      9                                           @profiler
>     10                                           def g():
>     11   1000001   1844697930   1844.7     63.6         for i in
> xrange(1000000):
>     12   1000000   1055333053   1055.3     36.4                 f()
>
> Which is what I would expect. Hmm

What platform are you on?

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
  -- Umberto Eco



More information about the NumPy-Discussion mailing list