Created
February 7, 2010 08:47
-
-
Save justinvanwinkle/297314 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
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: | |
accum.append(str(x)) | |
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: | |
f.write(str(x)) | |
return f.getvalue() | |
test_method(naive_way) | |
test_method(join_way) | |
test_method(join_for_way) | |
#test_method(mutable_way) | |
test_method(stringio_way) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment