Last active
August 29, 2015 14:06
-
-
Save cblair/6d4e51170c0da0e704ea to your computer and use it in GitHub Desktop.
Performance experiments with python string generation
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
#!/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