Python Speed

Steven D'Aprano steve+comp.lang.python at
Thu Feb 28 08:05:19 CET 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 information about the Python-list mailing list