Skip to content

Commit a46543d

Browse files
committed
Merge pull request #16 from Bouke/patches/2
Python 3 compatibility
2 parents 5046bde + c9b04a9 commit a46543d

File tree

13 files changed

+240
-181
lines changed

13 files changed

+240
-181
lines changed

djangobench/base_settings.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
ALLOWED_HOSTS = ['*']
2+
13
DATABASE_ENGINE = 'sqlite3'
24
DATABASE_NAME = ':memory:'
35

@@ -8,4 +10,4 @@
810
},
911
}
1012

11-
SECRET_KEY = "NOT REALLY SECRET"
13+
SECRET_KEY = "NOT REALLY SECRET"

djangobench/benchmarks/default_middleware/benchmark.py

+11-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from time import time
2-
31
from django.test.client import Client, FakePayload
42
from django.conf import global_settings
53
from django.conf import settings
@@ -8,6 +6,7 @@
86

97
from djangobench.utils import run_comparison_benchmark
108

9+
1110
class RequestFactory(Client):
1211
"""
1312
Class that lets you create mock Request objects for use in testing.
@@ -33,7 +32,7 @@ def request(self, **request):
3332
has created it.
3433
"""
3534
environ = {
36-
'HTTP_COOKIE': self.cookies,
35+
'HTTP_COOKIE': self.cookies.output(header='', sep='; '),
3736
'PATH_INFO': '/',
3837
'QUERY_STRING': '',
3938
'REQUEST_METHOD': 'GET',
@@ -48,6 +47,7 @@ def request(self, **request):
4847

4948
return WSGIRequest(environ)
5049

50+
5151
def setup():
5252
global req_factory, handler_default_middleware, handler_no_middleware
5353
req_factory = RequestFactory()
@@ -60,27 +60,31 @@ def setup():
6060
handler_no_middleware = WSGIHandler()
6161
handler_no_middleware.load_middleware()
6262

63+
6364
def benchmark_request(middleware_classes):
6465
settings.MIDDLEWARE_CLASSES = middleware_classes
6566
req_factory = RequestFactory()
6667
handler = WSGIHandler()
6768
handler.load_middleware()
6869
handler.get_response(req_factory.get('/'))
6970

71+
7072
def benchmark_default_middleware():
7173
global req_factory, handler_default_middleware
7274
handler_default_middleware.get_response(req_factory.get('/'))
7375

76+
7477
def benchmark_no_middleware():
7578
global req_factory, handler_no_middleware
7679
handler_no_middleware.get_response(req_factory.get('/'))
7780

81+
7882
run_comparison_benchmark(
7983
benchmark_default_middleware,
8084
benchmark_no_middleware,
81-
setup = setup,
82-
syncdb = False,
83-
meta = {
85+
setup=setup,
86+
syncdb=False,
87+
meta={
8488
'description': 'Request/response overhead added by the default middleware.',
8589
}
86-
)
90+
)
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
from unipath import FSPath as Path
1+
import os
2+
23
from djangobench.base_settings import *
34

45
USE_I18N = False
56
USE_L10N = True
6-
7-
TEMPLATE_DIRS = [Path(__file__).parent.child('templates').absolute()]
7+
TEMPLATE_DIRS = (
8+
os.path.abspath(os.path.join(os.path.dirname(__file__), 'templates')),
9+
)
810
INSTALLED_APPS = ['l10n_render']

djangobench/benchmarks/query_exists/benchmark.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from djangobench.utils import run_benchmark
22
from query_exists.models import Book
33

4+
45
def benchmark():
56
#Checking for object that exists
67
Book.objects.filter(id=1).exists()
@@ -11,9 +12,9 @@ def benchmark():
1112
if hasattr(Book.objects, 'exists'):
1213
run_benchmark(
1314
benchmark,
14-
meta = {
15+
meta={
1516
'description': 'A Model.objects.exists() call for both existing and non-existing objects.'
1617
}
1718
)
1819
else:
19-
print "SKIP: Django before 1.2 doesn't have QuerySet.exists()"
20+
print("SKIP: Django before 1.2 doesn't have QuerySet.exists()")

djangobench/benchmarks/query_get_or_create/benchmark.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44

55
counter = itertools.count(1)
66

7+
78
def benchmark():
8-
nextid = counter.next()
9-
9+
nextid = next(counter)
10+
1011
# This will do a create ...
1112
Book.objects.get_or_create(id=nextid, defaults={'title': 'hi'})
1213

@@ -15,7 +16,8 @@ def benchmark():
1516

1617
run_benchmark(
1718
benchmark,
18-
meta = {
19-
'description': 'A Model.objects.get_or_create() call, both for existing and non-existing objects.',
19+
meta={
20+
'description': 'A Model.objects.get_or_create() call, both for '
21+
'existing and non-existing objects.',
2022
}
2123
)

djangobench/benchmarks/query_prefetch_related/benchmark.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
from django import VERSION
33
from query_prefetch_related.models import Book, Author
44

5+
56
def benchmark():
6-
for i in xrange(10):
7+
for i in range(10):
78
for a in Author.objects.prefetch_related('books'):
89
list(a.books.all())
910

11+
1012
def setup():
1113
for i in range(0, 20):
1214
a = Author.objects.create(author="Author %s" % i)
@@ -22,7 +24,7 @@ def setup():
2224
run_benchmark(
2325
benchmark,
2426
setup=setup,
25-
meta = {
27+
meta={
2628
'description': 'A simple Model.objects.select_related() call.',
2729
}
2830
)
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
from djangobench.utils import run_benchmark
22
from query_select_related.models import Book
33

4+
45
def benchmark():
5-
for i in xrange(20):
6+
for i in range(20):
67
list(Book.objects.select_related('author'))
78

89
run_benchmark(
910
benchmark,
10-
meta = {
11+
meta={
1112
'description': 'A simple Model.objects.select_related() call.',
1213
}
1314
)

djangobench/benchmarks/template_render/benchmark.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ def benchmark_django_gt_13():
4949

5050
run_benchmark(
5151
benchmark_django_gt_13 if VERSION > (1, 3) else benchmark_django_lte_13,
52-
syncdb = False,
53-
meta = {
52+
syncdb=False,
53+
meta={
5454
'description': ('Render a somewhat complex, fairly typical template '
5555
'(including inheritance, reverse URL resolution, etc.).'),
5656
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
from unipath import FSPath as Path
1+
import os
2+
23
from djangobench.base_settings import *
34

45
INSTALLED_APPS = ['template_render']
5-
TEMPLATE_DIRS = [Path(__file__).parent.child('templates').absolute()]
6+
TEMPLATE_DIRS = (
7+
os.path.abspath(os.path.join(os.path.dirname(__file__), 'templates')),
8+
)
69
ROOT_URLCONF = 'template_render.urls'

0 commit comments

Comments
 (0)