Skip to content

Instantly share code, notes, and snippets.

@lepture
Created November 10, 2014 02:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lepture/4a2db575c07bcc0c4fad to your computer and use it in GitHub Desktop.
Save lepture/4a2db575c07bcc0c4fad to your computer and use it in GitHub Desktop.
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)
@lepture
Copy link
Author

lepture commented Nov 10, 2014

0.0101590156555
0.353223800659
0.328510046005

-----

0.0127718448639
0.34591794014
0.347246170044

-----

0.0113131999969
0.348247051239
0.337538003922

-----

0.012020111084
0.355268001556
0.343533992767

------

0.0097451210022
0.347717046738
0.357761144638

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment