Created
June 30, 2011 03:51
-
-
Save eklitzke/1055597 to your computer and use it in GitHub Desktop.
add_callback benchmark
This file contains hidden or 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
| 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