Skip to content

Instantly share code, notes, and snippets.

@defnull
Created August 28, 2011 18:57
Show Gist options
  • Save defnull/1177050 to your computer and use it in GitHub Desktop.
Save defnull/1177050 to your computer and use it in GitHub Desktop.
Small WSGI benchmark (removes the HTTP or socket layer)
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 = int(sys.argv[1]) if len(sys.argv) > 1 else 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 int(1/tpr)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment