Created
November 10, 2014 02:10
-
-
Save lepture/4a2db575c07bcc0c4fad 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
import time | |
j = range(100000) | |
def test_plus(): | |
out = '' | |
for i in j: | |
out += 'a' | |
return out | |
def test_format(): | |
out = '' | |
for i in j: | |
out = '{0}{1}'.format(out, 'a') | |
return out | |
def test_modulo(): | |
out = '' | |
for i in j: | |
out = '%s%s' % (out, 'a') | |
return out | |
def bench(fn): | |
start = time.time() | |
fn() | |
print(time.time() - start) | |
bench(test_plus) | |
bench(test_format) | |
bench(test_modulo) |
Author
lepture
commented
Nov 10, 2014
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment