Skip to content
Create a gist now

Instantly share code, notes, and snippets.

#!/usr/bin/env python
def test_method(method):
start_time = time.time()
result = method()
assert len(result) == 68888890, 'Method work no good: %s != 68888890' % len(result)
end_time = time.time()
print method.func_name, end_time - start_time
def naive_way():
accum = ''
for x in data:
accum += str(x)
return accum
def join_way():
return ''.join([str(x) for x in data])
def join_for_way():
accum = []
for x in data:
return ''.join(accum)
from UserString import MutableString
def mutable_way():
accum = MutableString()
for x in data:
accum += str(x)
return accum
from cStringIO import StringIO
def stringio_way():
f = StringIO()
for x in data:
return f.getvalue()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.