I noticed some odd results in string formatting performance
Code:
sam@oberon:~$ /usr/lib/python2.6/timeit.py '"%i"%1'
10000000 loops, best of 3: 0.0357 usec per loop
sam@oberon:~$ /usr/lib/python2.6/timeit.py '"%s"%1'
10000000 loops, best of 3: 0.0357 usec per loop
here %i and %s take identical time. i would slightly expect %i to win (%s is more generic so ought to do more checking).
Code:
sam@oberon:~$ /usr/lib/python2.6/timeit.py '"%i%i"%(1,2)'
1000000 loops, best of 3: 1.44 usec per loop
sam@oberon:~$ /usr/lib/python2.6/timeit.py '"%s%s"%(1,2)'
1000000 loops, best of 3: 0.361 usec per loop
now with 2 numbers. %s is 4 times faster than %i. i really would not expect the more generic function to win. also why the change. any ideas whats going on?
i have also tried python 2.7 and got the same result.
Bookmarks