Skip to content

Instantly share code, notes, and snippets.

@hktechn0
Created January 9, 2010 12:23
Show Gist options
  • Save hktechn0/272875 to your computer and use it in GitHub Desktop.
Save hktechn0/272875 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import datetime
loop = 500000
a = str()
s = datetime.datetime.now()
for i in range(loop):
for c in range(0x20, 0x7f):
a += chr(c)
e = datetime.datetime.now()
print e - s
b = list()
s = datetime.datetime.now()
for i in range(loop):
for c in range(0x20, 0x7f):
b.append(chr(c))
b = ''.join(b)
e = datetime.datetime.now()
print e - s
# $ time python strjoin_test.py
# 0:00:18.512737
# 0:00:20.663510
# python strjoin_test.py 27.92s user 11.05s system 99% cpu 39.242 total
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment