[Python-ideas] Interrogate alternate namespace keyword and concept

Steven D'Aprano steve at pearwood.info
Sat Aug 15 04:13:22 CEST 2009

On Sat, 15 Aug 2009 09:53:41 am Prozacgod wrote:
> This makes sense, obviously you should compile it first, which when
> executed should execute exactly the same as the original context
> python.

We want to compare the speed of the following statement:

test.value += 1

with the equivalent:

code = compile("value += 1", '', 'exec')
exec code in test.__dict__

Why do you think it is appropriate to ignore the time taken by the 
compile() when comparing the two? Put it this way: if you want to know 
how long it takes to make fresh stir-fried chicken, you have to include 
the ten minutes it takes to chop up the vegetables and chicken, and not 
just the two minutes it takes to stir-fry them.

Steven D'Aprano

More information about the Python-ideas mailing list