Skip to content

Instantly share code, notes, and snippets.

@zed
Created November 6, 2010 15:03
Show Gist options
  • Select an option

  • Save zed/665475 to your computer and use it in GitHub Desktop.

Select an option

Save zed/665475 to your computer and use it in GitHub Desktop.
time performance: string.join vs. string.__add__
#!/usr/bin/env python
from profilestats import profile # $ pip install profilestats
def join_join(a, b):
return ','.join([a, b])
def join_plus(a, b):
return a + ',' + b
@profile
def test():
N = 10**4
for a, b in generate_str_pairs(N):
assert join_plus(a, b) == join_join(a, b)
for a, b in generate_str_pairs(N):
assert join_join(a, b) == join_plus(a, b)
def generate_str_pairs(n):
for i in xrange(n):
yield 'a'*i, 'b'*i
if __name__ == "__main__":
test()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment