Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: Python Speed

Reply
Thread Tools

Re: Python Speed

 
 
Steven D'Aprano
Guest
Posts: n/a
 
      02-28-2013
On Wed, 27 Feb 2013 21:11:25 -0500, Terry Reedy wrote:

> There is a problem with timer overhead for sub-microsecond operations.
> In interactive use, the code is compiled within a function that gets
> called. The string 'abc需' should be stored as a constant in the code
> object. To force repeated string operation, one should either time from
> command line or do an operation, as with the example above. I notice
> that the first of 3 times is almost always higher for some reason.


I am not an expert on this, but I suspect the problem may have something
to do with CPU pipelines and cache. The first time the timer runs, the
cache is empty, and you get a slightly higher time. Subsequently there
are not as many CPU cache misses, and the code runs more quickly.

Or, I could be talking out of my arse. Once upon a time CPUs were simple
enough for me to understand what make code faster or slower, but no
more...


--
Steven
 
Reply With Quote
 
 
 
 
Stefan Behnel
Guest
Posts: n/a
 
      02-28-2013
Steven D'Aprano, 28.02.2013 08:05:
> On Wed, 27 Feb 2013 21:11:25 -0500, Terry Reedy wrote:
>
>> There is a problem with timer overhead for sub-microsecond operations.
>> In interactive use, the code is compiled within a function that gets
>> called. The string 'abc需' should be stored as a constant in the code
>> object. To force repeated string operation, one should either time from
>> command line or do an operation, as with the example above. I notice
>> that the first of 3 times is almost always higher for some reason.

>
> I am not an expert on this, but I suspect the problem may have something
> to do with CPU pipelines and cache. The first time the timer runs, the
> cache is empty, and you get a slightly higher time. Subsequently there
> are not as many CPU cache misses, and the code runs more quickly.


Well, the default loop iteration count is 1000000, so warming up any caches
might make a little difference at the very beginning but should rarely have
a major impact on the overall running time, as each iteration only changes
the final result by 1/1000000 of its runtime.

However, it's best to run timeit as a main program (python -m timeit),
because the way it works then is that it first runs the code a couple of
times to see how often it should repeat it in a loop to get meaningful
results. Only *then* it starts benchmarking it. That initial testing phase
should usually be enough to warm up any caches, so that you'd get better
results. You can still get the results of all repeated runs if you pass -v.

Stefan


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Reported Wireless speed w/ repeater 7-9x Measured Speed Lance Wireless Networking 0 10-31-2004 09:31 PM
I need speed Mr .Net....speed Ham ASP .Net 6 10-29-2004 08:04 AM
speed speed speed a.metselaar Computer Support 14 12-30-2003 03:34 AM
java tool to test disk i/o, processor speed, and network speed efiedler Java 1 10-09-2003 03:36 PM
USB High Speed against USB Non High Speed DannyD1355 Computer Support 1 09-07-2003 02:59 AM



Advertisments