Created
June 20, 2011 22:51
-
-
Save defnull/1036791 to your computer and use it in GitHub Desktop.
Bottle "Hello World" benchmark
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
import sys | |
import bottle | |
from time import time | |
app = bottle.Bottle() | |
@app.route('/') | |
def hello(): | |
return 'Hello World!' | |
def bench(n): | |
''' Process n requests and return the average time per request. ''' | |
start = time() | |
for i in range(n): | |
app({'PATH_INFO':'/', 'REQUEST_METHOD':'GET'}, lambda x,y: y) | |
return (time() - start) / n | |
n = 500 | |
# Run n tests with 1 to n requests per run. Return the minimum | |
# average time per request. | |
tpr = min(bench(i) for i in range(1,n+1)) | |
# Print requests per second (instead of seconds per request). | |
print 'Requests per second: %d' % (1/tpr) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment