annotate contrib/raw_wsgi_bench.py @ 6033:f70b9ab3dedc

fix return type of get_by_... lookup functions (must be User obj or None)
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Fri, 28 Feb 2014 19:38:41 +0100
parents 1d3d282130c8
children
rev   line source
4219
ce1265ca021a First very basic in-circuit benchmark for WSGI
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
ce1265ca021a First very basic in-circuit benchmark for WSGI
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
2 """
ce1265ca021a First very basic in-circuit benchmark for WSGI
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
3 MoinMoin - raw_wsgi_bench
ce1265ca021a First very basic in-circuit benchmark for WSGI
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
4
ce1265ca021a First very basic in-circuit benchmark for WSGI
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
5 @copyright: 2008 MoinMoin:FlorianKrupicka
ce1265ca021a First very basic in-circuit benchmark for WSGI
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
6 @license: GNU GPL, see COPYING for details.
ce1265ca021a First very basic in-circuit benchmark for WSGI
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
7 """
ce1265ca021a First very basic in-circuit benchmark for WSGI
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
8 import time, itertools, sys, os
ce1265ca021a First very basic in-circuit benchmark for WSGI
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
9
ce1265ca021a First very basic in-circuit benchmark for WSGI
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
10 from werkzeug.test import Client
ce1265ca021a First very basic in-circuit benchmark for WSGI
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
11
ce1265ca021a First very basic in-circuit benchmark for WSGI
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
12 from MoinMoin.wsgiapp import application
ce1265ca021a First very basic in-circuit benchmark for WSGI
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
13
ce1265ca021a First very basic in-circuit benchmark for WSGI
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
14 sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'tests'))
ce1265ca021a First very basic in-circuit benchmark for WSGI
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
15
ce1265ca021a First very basic in-circuit benchmark for WSGI
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
16 RUNS = 100
ce1265ca021a First very basic in-circuit benchmark for WSGI
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
17 RUNS_MARKER = RUNS / 10
ce1265ca021a First very basic in-circuit benchmark for WSGI
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
18 DOTS_MARKER = RUNS_MARKER / 5
ce1265ca021a First very basic in-circuit benchmark for WSGI
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
19
ce1265ca021a First very basic in-circuit benchmark for WSGI
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
20 PAGES = ('FrontPage', 'HelpOnMoinWikiSyntax', 'RecentChanges')
ce1265ca021a First very basic in-circuit benchmark for WSGI
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
21
ce1265ca021a First very basic in-circuit benchmark for WSGI
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
22 client = Client(application)
ce1265ca021a First very basic in-circuit benchmark for WSGI
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
23
ce1265ca021a First very basic in-circuit benchmark for WSGI
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
24 for page in PAGES:
ce1265ca021a First very basic in-circuit benchmark for WSGI
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
25 print '=== Run with page "%s" ===' % page
ce1265ca021a First very basic in-circuit benchmark for WSGI
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
26 print 'Running %i WSGI-requests:' % RUNS
ce1265ca021a First very basic in-circuit benchmark for WSGI
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
27 timing = time.time()
ce1265ca021a First very basic in-circuit benchmark for WSGI
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
28 for run in xrange(RUNS):
ce1265ca021a First very basic in-circuit benchmark for WSGI
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
29 appiter, status, headers = client.get('/%s' % page)
ce1265ca021a First very basic in-circuit benchmark for WSGI
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
30 #result = ''.join(appiter)
ce1265ca021a First very basic in-circuit benchmark for WSGI
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
31 if ((run + 1) % RUNS_MARKER == 0):
ce1265ca021a First very basic in-circuit benchmark for WSGI
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
32 sys.stdout.write('%i' % (run + 1))
ce1265ca021a First very basic in-circuit benchmark for WSGI
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
33 elif ((run + 1) % DOTS_MARKER == 0):
ce1265ca021a First very basic in-circuit benchmark for WSGI
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
34 sys.stdout.write('.')
ce1265ca021a First very basic in-circuit benchmark for WSGI
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
35 timing = time.time() - timing
ce1265ca021a First very basic in-circuit benchmark for WSGI
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
36
ce1265ca021a First very basic in-circuit benchmark for WSGI
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
37 print
ce1265ca021a First very basic in-circuit benchmark for WSGI
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
38 print 'Finished %i WSGI-requests in %.2f seconds' % (RUNS, timing)
ce1265ca021a First very basic in-circuit benchmark for WSGI
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
39 print 'Time per request: %.4f seconds' % (timing / RUNS)
ce1265ca021a First very basic in-circuit benchmark for WSGI
Florian Krupicka <florian.krupicka@googlemail.com>
parents:
diff changeset
40 print 'Requests per second: %.2f' % (RUNS / timing)