Created
June 17, 2014 20:16
-
-
Save gdvalle/bee94926983b65fa5508 to your computer and use it in GitHub Desktop.
Script to test speed of filter_leading_non_json_lines()
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 python | |
import timeit | |
import sys | |
try: | |
count = int(sys.argv[1]) | |
except: | |
count = 1 | |
try: | |
string_size = int(sys.argv[2]) | |
except: | |
string_size = 60000 | |
try: | |
string = sys.argv[3] | |
except: | |
string = 'X' | |
def show_results(result, count=count, string_size=string_size): | |
"Print results in terms of microseconds per pass and per item." | |
per_pass = 1000000 * (result / count) | |
print '%.2f usec/pass' % per_pass, | |
per_item = per_pass / string_size | |
print '%.2f usec/item' % per_item | |
if __name__ == '__main__': | |
setup = """ | |
string='"""+string+"""' | |
string_size="""+str(string_size)+""" | |
from utils import filter_leading_non_json_lines | |
buf = '{"content": "' + string * string_size + '=", "changed": false, "encoding": "base64"}' | |
""" | |
test = "filter_leading_non_json_lines(buf)" | |
t = timeit.Timer(test, setup) | |
show_results(t.timeit(number=count)) | |
print('Count: {}'.format(count)) | |
print('String Size: {}'.format(string_size)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment