Skip to content

Instantly share code, notes, and snippets.

@defnull
Created June 20, 2011 22:51
Show Gist options
  • Save defnull/1036791 to your computer and use it in GitHub Desktop.
Save defnull/1036791 to your computer and use it in GitHub Desktop.
Bottle "Hello World" benchmark
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