Skip to content

Instantly share code, notes, and snippets.

@derpston
Created March 7, 2012 02:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save derpston/1990503 to your computer and use it in GitHub Desktop.
Save derpston/1990503 to your computer and use it in GitHub Desktop.
Metricfire Python benchmarking
import metricfire
import time
# Send to a nonexistant Metricfire aggregation server on this machine.
metricfire.init("deadbeef-dead-beef-dead-deadcafebabe", server = "127.0.0.1:6334")
before = time.time()
for index in xrange(100000):
pass
after = time.time()
plain_usecs_per_iteration = (after - before) / 100000 * 1000000
print "100k iterations in %fs, %fus per iteration" % (after - before, plain_usecs_per_iteration)
before = time.time()
for index in xrange(100000):
metricfire.send("test", 1)
after = time.time()
send_usecs_per_iteration = (after - before) / 100000 * 1000000
print "100k iterations in %fs, %fus per iteration" % (after - before, send_usecs_per_iteration)
def foo():
pass
@metricfire.measure
def foo2():
pass
before = time.time()
for index in xrange(100000):
foo()
after = time.time()
usecs_per_call = (after - before) / 100000 * 1000000
print "100k calls in %fs, %fus per call" % (after - before, usecs_per_call)
before = time.time()
for index in xrange(100000):
foo2()
after = time.time()
decorated_usecs_per_call = (after - before) / 100000 * 1000000
print "100k decorated calls in %fs, %fus per call" % (after - before, decorated_usecs_per_call)
@derpston
Copy link
Author

derpston commented Mar 7, 2012

Results from an Intel(R) Core(TM) i7 CPU 950 @ 3.07GHz

100k iterations in 0.003448s, 0.034480us per iteration
100k iterations in 4.899722s, 48.997221us per iteration
100k calls in 0.010108s, 0.101080us per call
100k decorated calls in 5.416182s, 54.161820us per call

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment