Skip to content

Instantly share code, notes, and snippets.

@cblair
Last active August 29, 2015 14:06
Show Gist options
  • Save cblair/6d4e51170c0da0e704ea to your computer and use it in GitHub Desktop.
Save cblair/6d4e51170c0da0e704ea to your computer and use it in GitHub Desktop.
Performance experiments with python string generation
#!/usr/bin/env python2.7
import random
import numpy
def gen_random_string(range_start, range_end, str_len):
#~.145 s
return "".join(
[
"x%04x" %\
#~.051 s
random.randint(range_start, range_end)
#~.?
#numpy.random.randint(range_start, range_end)
for x in range(0, str_len)
]
)
def gen_random_strings():
#Generate 100 random strings.
#~.239 s
strings = []
for i in range(0, 100):
strings.append(gen_random_string(32, 300, 300))
gen_random_strings()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment