Skip to content

Instantly share code, notes, and snippets.

@andreibaranouski
Created January 14, 2016 16:53
Show Gist options
  • Save andreibaranouski/9e88e7f307286d1d3268 to your computer and use it in GitHub Desktop.
Save andreibaranouski/9e88e7f307286d1d3268 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import cProfile
import pstats
import StringIO
import json
from spring.docgen import NewDocument, NewKey
def generate_keys():
new_keys = NewKey(prefix=None, expiration=0)
return tuple(new_keys.next(i)[0] for i in xrange(500000))
def run(keys):
total_size = 0
docs = NewDocument(avg_size=1024)
for key in keys:
d = docs.next(key)
total_size += len(json.dumps(docs.next(key)))
return total_size / len(keys)
def profile():
pr = cProfile.Profile()
s = StringIO.StringIO()
keys = generate_keys()
# print keys
pr.enable()
avg_size = run(keys)
pr.disable()
print "avg_size", avg_size
ps = pstats.Stats(pr, stream=s).sort_stats('tottime')
ps.reverse_order()
ps.print_stats()
ps.dump_stats('profile.prof')
if __name__ == '__main__':
profile()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment