22 ms·
Your timeit calls in the edit need the -s parameter before the first statements, so they aren't executed on each loop iteration. The overhead is in creating the
by zwegner 11y ago
Your timeit calls in the edit need the -s parameter before the first statements, so they aren't executed on each loop iteration. The overhead is in creating the class, not the instances.
$ python3 -mtimeit -s 's="%s %s %s"' 's % (1, 3, 9)'
1000000 loops, best of 3: 0.343 usec per loop
$ python3 -mtimeit -s 'class Spam:pass' 'Spam()'
10000000 loops, best of 3: 0.106 usec per loop
- dalke 11y agoThanks! That's a big forehead smack on my side. The numbers are more in line with what I expected. Meaning it is possible to defer some of the time cost by using a single constructor rather than evaluating the string.