Skip to content

Commit f4100ff

Browse files
Updated benchmarks to work on latest Django main (#41)
1 parent 86e42a1 commit f4100ff

File tree

10 files changed

+113
-76
lines changed

10 files changed

+113
-76
lines changed
Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1-
try:
2-
from django.conf.urls import url
3-
except ImportError:
4-
from django.conf.urls.defaults import url
1+
import django
52

63
from .views import index
74

5+
if django.VERSION >= (2, 0):
6+
from django.urls import re_path
7+
elif django.VERSION >= (1, 4):
8+
from django.conf.urls import url as re_path
9+
else:
10+
from django.conf.urls.defaults import url as re_path
11+
12+
813
urlpatterns = [
9-
url(r'^.*$', index),
14+
re_path(r'^.*$', index),
1015
]

djangobench/benchmarks/template_render/templates/permalink.html

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,44 +46,44 @@ <h2 class="wide-heading">
4646
{% endif %}
4747
<div class="clear"></div>
4848

49-
{% ifnotequal num1 1 %}
49+
{% if num1 != 1 %}
5050
{% if not object3 %}
51-
{% ifnotequal 1 num2 %}
51+
{% if 1 != num2 %}
5252
{{ num2 }}
5353
{% else %}
5454
<p>Nothing</p>
55-
{% endifnotequal %}
55+
{% endif %}
5656
{% else %}
5757
{{ num1 }}
5858
{% endif %}
59-
{% endifnotequal %}
59+
{% endif %}
6060
<div class="clear"></div>
6161

62-
{% ifnotequal num2 0 %}
62+
{% if num2 != 0 %}
6363
{% if not object3 %}
64-
{% ifnotequal 1 num2 %}
64+
{% if 1 != num2 %}
6565
{{ num2 }}
6666
{% else %}
6767
<p>Nothing</p>
68-
{% endifnotequal %}
68+
{% endif %}
6969
{% else %}
7070
{{ num1 }}
7171
{% endif %}
72-
{% endifnotequal %}
72+
{% endif %}
7373
<div class="clear"></div>
7474

7575

76-
{% ifnotequal num1 0 %}
76+
{% if num1 != 0 %}
7777
{% if not object3 %}
78-
{% ifnotequal 1 num2 %}
78+
{% if 1 != num2 %}
7979
{{ num2 }}
8080
{% else %}
8181
<p>Nothing</p>
82-
{% endifnotequal %}
82+
{% endif %}
8383
{% else %}
8484
{{ num1 }}
8585
{% endif %}
86-
{% endifnotequal %}
86+
{% endif %}
8787
<div class="clear"></div>
8888

8989
{% include "for_loop.html" %}

djangobench/benchmarks/template_render/templates/permalink_django_lte_13.html

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,44 +46,44 @@ <h2 class="wide-heading">
4646
{% endif %}
4747
<div class="clear"></div>
4848

49-
{% ifnotequal num1 1 %}
49+
{% if num1 != 1 %}
5050
{% if not object3 %}
51-
{% ifnotequal 1 num2 %}
51+
{% if 1 != num2 %}
5252
{{ num2 }}
5353
{% else %}
5454
<p>Nothing</p>
55-
{% endifnotequal %}
55+
{% endif %}
5656
{% else %}
5757
{{ num1 }}
5858
{% endif %}
59-
{% endifnotequal %}
59+
{% endif %}
6060
<div class="clear"></div>
6161

62-
{% ifnotequal num2 0 %}
62+
{% if num2 != 0 %}
6363
{% if not object3 %}
64-
{% ifnotequal 1 num2 %}
64+
{% if 1 != num2 %}
6565
{{ num2 }}
6666
{% else %}
6767
<p>Nothing</p>
68-
{% endifnotequal %}
68+
{% endif %}
6969
{% else %}
7070
{{ num1 }}
7171
{% endif %}
72-
{% endifnotequal %}
72+
{% endif %}
7373
<div class="clear"></div>
7474

7575

76-
{% ifnotequal num1 0 %}
76+
{% if num1 != 0 %}
7777
{% if not object3 %}
78-
{% ifnotequal 1 num2 %}
78+
{% if 1 != num2 %}
7979
{{ num2 }}
8080
{% else %}
8181
<p>Nothing</p>
82-
{% endifnotequal %}
82+
{% endif %}
8383
{% else %}
8484
{{ num1 }}
8585
{% endif %}
86-
{% endifnotequal %}
86+
{% endif %}
8787
<div class="clear"></div>
8888

8989
{% include "for_loop.html" %}
Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1-
try:
2-
from django.conf.urls import url
3-
except ImportError:
4-
from django.conf.urls.defaults import url
1+
import django
52

63
from .views import join, login, logout
74

5+
if django.VERSION >= (2, 0):
6+
from django.urls import re_path
7+
elif django.VERSION >= (1, 4):
8+
from django.conf.urls import url as re_path
9+
else:
10+
from django.conf.urls.defaults import url as re_path
11+
12+
813
urlpatterns = [
9-
url(r'/join/?$', join, name='join'),
10-
url(r'/login/?$', login, name='login'),
11-
url(r'/logout/?$', logout, name='logout'),
14+
re_path(r'/join/?$', join, name='join'),
15+
re_path(r'/login/?$', login, name='login'),
16+
re_path(r'/logout/?$', logout, name='logout'),
1217
]
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
from django.http import HttpResponse
2+
3+
14
# some dummy classes for the url reverse
25
def join(request):
3-
pass
6+
return HttpResponse()
47

58
def login(request):
6-
pass
9+
return HttpResponse()
710

811
def logout(request):
9-
pass
12+
return HttpResponse()
Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
1-
from django.conf.urls import url
1+
import django
22

33
from . import views
44

5+
if django.VERSION >= (2, 0):
6+
from django.urls import re_path
7+
elif django.VERSION >= (1, 4):
8+
from django.conf.urls import url as re_path
9+
else:
10+
from django.conf.urls.defaults import url as re_path
11+
512

613
def generate_filler_patterns(num=1):
714
""" Returns a list of url pattern inputs for garbage views """
815
for n in range(num):
9-
yield url(r''.join((r'^', r'x' * 3 * n, r'/$')), views.basic)
16+
yield re_path(r''.join((r'^', r'x' * 3 * n, r'/$')), views.basic)
1017

1118
urlpatterns = list(generate_filler_patterns(10))
12-
urlpatterns.append(url(r'^basic/$', views.basic, name='basic'))
13-
urlpatterns.append(url(r'^[a-z]*/$', views.catchall, name='catchall'))
14-
urlpatterns.append(url(r'^replace/(?P<var>.*?)', views.vars, name='vars'))
19+
urlpatterns.append(re_path(r'^basic/$', views.basic, name='basic'))
20+
urlpatterns.append(re_path(r'^[a-z]*/$', views.catchall, name='catchall'))
21+
urlpatterns.append(re_path(r'^replace/(?P<var>.*?)', views.vars, name='vars'))
Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
def basic():
2-
pass
1+
from django.http import HttpResponse
32

4-
def catchall():
5-
pass
3+
def basic(request):
4+
return HttpResponse()
65

7-
def vars(var=None):
8-
pass
6+
def catchall(request):
7+
return HttpResponse()
8+
9+
def vars(request, var=None):
10+
return HttpResponse()
Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,32 @@
1-
try:
2-
from django.conf.urls import url
3-
except ImportError:
4-
from django.conf.urls.defaults import url
1+
import django
2+
from django.http import HttpResponse
3+
4+
if django.VERSION >= (2, 0):
5+
from django.urls import re_path
6+
elif django.VERSION >= (1, 4):
7+
from django.conf.urls import url as re_path
8+
else:
9+
from django.conf.urls.defaults import url as re_path
510

611
def ok_view(request, *a, **kw):
7-
pass
12+
return HttpResponse()
813

914
def handler404(request):
10-
pass
15+
return HttpResponse()
1116

1217
sections = ["section%d" % i for i in range(10)]
1318
features = ["feature%d" % i for i in range(20)]
1419

1520
urlpatterns = [
16-
url("^%s/%s$" % (s, f), ok_view) for s in sections for f in features
21+
re_path("^%s/%s$" % (s, f), ok_view) for s in sections for f in features
1722
]
1823

1924
urlpatterns += [
20-
url(r"^(?P<locale>en|ru)/%s$" % f, ok_view) for f in features
25+
re_path(r"^(?P<locale>en|ru)/%s$" % f, ok_view) for f in features
2126
]
2227

2328
urlpatterns += [
24-
url(r"^(?P<user>\w+)/(?P<repo>\w+)/%s$" % f, ok_view) for f in features
29+
re_path(r"^(?P<user>\w+)/(?P<repo>\w+)/%s$" % f, ok_view) for f in features
2530
]
2631

2732
# Total: 240 patterns
Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,32 @@
1-
try:
2-
from django.conf.urls import url
3-
except ImportError:
4-
from django.conf.urls.defaults import url
1+
import django
2+
from django.http import HttpResponse
3+
4+
if django.VERSION >= (2, 0):
5+
from django.urls import re_path
6+
elif django.VERSION >= (1, 4):
7+
from django.conf.urls import url as re_path
8+
else:
9+
from django.conf.urls.defaults import url as re_path
510

611
def ok_view(request, *a, **kw):
7-
pass
12+
return HttpResponse()
813

914
def handler404(request):
10-
pass
15+
return HttpResponse()
1116

1217
sections = ["section%d" % i for i in range(10)]
1318
features = ["feature%d" % i for i in range(20)]
1419

1520
urlpatterns = [
16-
url("^%s/%s$" % (s, f), ok_view) for s in sections for f in features
21+
re_path("^%s/%s$" % (s, f), ok_view) for s in sections for f in features
1722
]
1823

1924
urlpatterns += [
20-
url(r"^(?P<locale>en|ru)/%s$" % f, ok_view) for f in features
25+
re_path(r"^(?P<locale>en|ru)/%s$" % f, ok_view) for f in features
2126
]
2227

2328
urlpatterns += [
24-
url(r"^(?P<user>\w+)/(?P<repo>\w+)/%s$" % f, ok_view) for f in features
29+
re_path(r"^(?P<user>\w+)/(?P<repo>\w+)/%s$" % f, ok_view) for f in features
2530
]
2631

2732
# Total: 240 patterns
Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
import string
22

3-
try:
4-
from django.conf.urls import include, url
5-
except ImportError:
6-
from django.conf.urls.defaults import include, url
3+
import django
4+
from django.http import HttpResponse
5+
6+
if django.VERSION >= (2, 0):
7+
from django.urls import include, re_path
8+
elif django.VERSION >= (1, 4):
9+
from django.conf.urls import include, url as re_path
10+
else:
11+
from django.conf.urls.defaults import include, url as re_path
712

813

914
def ok_view(request, *a, **kw):
10-
pass
15+
return HttpResponse()
1116

1217
def handler500(request):
13-
pass
18+
return HttpResponse()
1419

15-
leaf_patterns = [url(r"^leaf$", ok_view)]
20+
leaf_patterns = [re_path(r"^leaf$", ok_view)]
1621

1722
def int2ascii(x, mod, alphabet=string.digits + string.ascii_letters):
1823
alphabet = alphabet[:mod]
@@ -26,7 +31,7 @@ def pattern_tree(parent, height, level):
2631
if height == 0:
2732
return leaf_patterns
2833
ids = [parent + int2ascii(i, level) for i in range(level)]
29-
return [url("^%s/" % id_, include(pattern_tree(id_, height - 1, level))) for id_ in ids]
34+
return [re_path("^%s/" % id_, include(pattern_tree(id_, height - 1, level))) for id_ in ids]
3035

3136
urlpatterns = pattern_tree("", 8, 2)
3237
# Total: 2**8 = 256 leafs, 511 nodes

0 commit comments

Comments
 (0)