Skip to content

Instantly share code, notes, and snippets.

@eklitzke
Created June 30, 2011 03:51
Show Gist options
  • Select an option

  • Save eklitzke/1055597 to your computer and use it in GitHub Desktop.

Select an option

Save eklitzke/1055597 to your computer and use it in GitHub Desktop.
add_callback benchmark
import optparse
import time
from tornado.ioloop import IOLoop
def main(iterations):
loop = IOLoop.instance()
counter = [0]
def callback(*args):
counter[0] += 1
if counter[0] < iterations:
loop.add_callback(callback)
else:
loop.stop()
loop.add_callback(callback)
loop.start()
if __name__ == '__main__':
parser = optparse.OptionParser()
parser.add_option('-n', dest='num_iterations', type='int', default=100000, help='Number of iterations to run')
opts, args = parser.parse_args()
t0 = time.time()
main(opts.num_iterations)
print time.time() - t0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment