Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

executable file 69 lines (47 sloc) 1.724 kB
#!/usr/bin/env python
import os, time, gc
os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.settings'
verbosity = 1
interactive = False
fixtures = ['basic']
from operator import itemgetter
def run_benchmarks(tests):
for name, test in tests:
time, clock = bench_test(test)
print '%s\ttime: %.2fms\tclock: %.2fms' % (name, time * 1000, clock * 1000)
def bench_test(test):
if 'prepare_once' in test:
test['prepare_once']()
total = 0
n = 1
while total < 2:
gc.disable()
l = [bench_once(test) for i in range(n)]
gc.enable()
total = sum(map(itemgetter(0), l))
# print [int(x * 1000000) for x in [total / n, min(l), max(l),
# sum(norm) / len(norm), min(norm), max(norm)]]
n *= 2
# print len(l)
s = sorted(l)
norm = s[n/8:-n/8] if n / 8 else s
norm_time = [r[0] for r in l]
norm_clock = [r[1] for r in l]
# return total * 2 / n # Or use normalized?
return sum(norm_time) / len(norm_time), sum(norm_clock) / len(norm_clock)
def bench_once(test):
if 'prepare' in test:
test['prepare']()
start = time.time()
clock = time.clock()
test['run']()
return (time.time() - start, time.clock() - clock)
from django.db import connection
from django.core.management import call_command
# Create a test database.
db_name = connection.creation.create_test_db(verbosity=verbosity, autoclobber=not interactive)
# Import the fixture data into the test database.
call_command('loaddata', *fixtures, **{'verbosity': verbosity})
from tests.bench import TESTS
run_benchmarks(TESTS)
connection.creation.destroy_test_db(db_name, verbosity=verbosity)
Jump to Line
Something went wrong with that request. Please try again.