Created
August 16, 2016 07:36
-
-
Save bittner/d105bf7e1d75712d812ac89837df8f59 to your computer and use it in GitHub Desktop.
This file contains 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
# Python string concatenation | |
# Appending strings to an existing string is way faster than prepending. | |
# Source: https://groups.google.com/d/msg/comp.lang.python/AzYJ0LAWe-w/wBLtn5BJIBsJ | |
python -m timeit -s "v = 'x' * 10; out = ''" "out = out + v" | |
# prints: 10000000 loops, best of 3: 0.0511 usec per loop | |
python -m timeit -s "v = 'x' * 10; out = ''" "out = v + out" | |
# prints: 100000 loops, best of 3: 52.7 usec per loop | |
python -m timeit -s "v = 'x' * 10; out = ''" "out += v" | |
# prints: 10000000 loops, best of 3: 0.053 usec per loop |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment