Created
December 1, 2010 08:05
-
-
Save sumeet/723145 to your computer and use it in GitHub Desktop.
String concatenation in CPython 2.7 and PyPy 1.4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(12:01a) (sumeet@shanoa:~)$ `which python2.7` ./timethese.py string_concat.py 10000000 | |
# Running code block #1 | |
assert ''.join(('abc', 'def', 'ghi')) == 'abcdefghi' | |
Took 2.855692 seconds to run 10000000 times. | |
# Running code block #2 | |
assert 'abc' + 'def' + 'ghi' == 'abcdefghi' | |
Took 0.762806 seconds to run 10000000 times. | |
# Running code block #3 | |
assert '%s%s%s' % ('abc', 'def', 'ghi') == 'abcdefghi' | |
Took 3.625320 seconds to run 10000000 times. | |
(12:01a) (sumeet@shanoa:~)$ `which pypy` ./timethese.py string_concat.py 10000000 | |
# Running code block #1 | |
assert ''.join(('abc', 'def', 'ghi')) == 'abcdefghi' | |
Took 2.484319 seconds to run 10000000 times. | |
# Running code block #2 | |
assert 'abc' + 'def' + 'ghi' == 'abcdefghi' | |
Took 0.034994 seconds to run 10000000 times. | |
# Running code block #3 | |
assert '%s%s%s' % ('abc', 'def', 'ghi') == 'abcdefghi' | |
Took 0.034827 seconds to run 10000000 times. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment