[Python-Dev] Silly little benchmark

Skip Montanaro skip@pobox.com (Skip Montanaro)
Thu, 12 Jul 2001 10:54:26 -0500


    Thomas> Don't forget to do meaningful performance comparisons before and
    Thomas> after ;P

It's that adjective "meaningful" that makes it difficult...  Obviously
pystone wouldn't be meaningful since it doesn't do much string stuff.  I
tried timing the following:

    PYTHONPATH= time ./python -tt ../Lib/test/regrtest.py -l

after making sure the .py[co] files were deleted.  I got "102.96user
1.47system" before and "103.24user 1.57system" after.  I then removed the
.py[co] files again and ran the same test under gdb, with breakpoints in
each of the three branches whose break commands incremented counters.  After
letting it run for *a while*, I got tired of waiting for it to complete (it
was in the midst of test___all__).  I broke into the debugger then examined
the counters.  The int/int branch had been taken 5432 times, the
string/string branch had been taken 635 times and the else branch 673 times.
It would appear that string/string add is perhaps the second-most executed
type of add, but that it is executed infrequently enough (at least by the
test suite) that special-casing it will have no effect.  Still, if you are
doing lots of string concatenation, perhaps looking at other methods (append
to list, then join the result, for example) would be worthwhile.

Skip