[Numpy-discussion] python numpy code many times slower than c++
Wes McKinney
wesmckinn@gmail....
Thu Jan 22 17:00:52 CST 2009
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
On Thu, Jan 22, 2009 at 2:52 AM, Robert Kern <robert.kern@gmail.com> wrote:
> On Thu, Jan 22, 2009 at 01:46, Hanni Ali <hanni.ali@gmail.com> wrote:
> > I have been using your profiler extensively and it has contributed to my
> > achieving significant improvements in the application I work on largely
> due
> > to the usefulness of the line by line breakdown enabling me to easily
> select
> > the next part of code to work on optimizing. So firstly many thanks for
> > writing it.
>
> My pleasure.
>
> > However back to my point, Wes, I have also experienced timing oddities,
> in
> > particular on Virtual machines (MS Hyper-V has very poor processor
> timings,
> > the older MS VM works fine though). I believe the negative timings arise
> > when the CPU (be it virtual or possibly physical) deviates from its
> standard
> > performance or rather the initial timer unit taken, would this make sense
> to
> > you Robert?
>
> Can you try using cProfile with lots of calls to empty functions? I'm
> using the same timer functions as cProfile.
>
> --
> 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
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20090122/9daddaf0/attachment.html
More information about the Numpy-discussion
mailing list