Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #11 from lqc/resolver_bench

Added two resolver benchmarks
  • Loading branch information...
commit 6ce444a8ee93c6f57f32889c3127f0728e2ac6d4 2 parents 05ca129 + c8dedf8
@jacobian jacobian authored
View
1  djangobench/benchmarks/url_resolve_flat/__init__.py
@@ -0,0 +1 @@
+
View
20 djangobench/benchmarks/url_resolve_flat/benchmark.py
@@ -0,0 +1,20 @@
+from django.core.urlresolvers import resolve
+from djangobench.utils import run_benchmark
+
+def benchmark():
+ for path in (
+ '/user/repo/feature19',
+ '/section0/feature0',
+ '/en/feature10',
+ '/ru/feature10',
+ '/missing'):
+ try:
+ resolve(path)
+ except:
+ pass
+run_benchmark(
+ benchmark,
+ meta = {
+ 'description': 'URL resolution with long-flat list of patterns.',
+ }
+)
View
4 djangobench/benchmarks/url_resolve_flat/settings.py
@@ -0,0 +1,4 @@
+from djangobench.base_settings import *
+
+INSTALLED_APPS = ['url_resolve_flat']
+ROOT_URLCONF = 'url_resolve_flat.urls'
View
25 djangobench/benchmarks/url_resolve_flat/urls.py
@@ -0,0 +1,25 @@
+from django.conf.urls.defaults import patterns, include, url
+
+def ok_view(request, *a, **kw):
+ pass
+
+def handler500(request):
+ pass
+
+sections = ["section%d" % i for i in range(10)]
+features = ["feature%d" % i for i in range(20)]
+
+urlpatterns = patterns('', *[
+ url("^%s/%s$" % (s, f), ok_view) for s in sections for f in features
+])
+
+urlpatterns += patterns('', *[
+ url("^(?P<locale>en|ru)/%s$" % f, ok_view)
+ for s in sections for f in features
+])
+
+urlpatterns += patterns('', *[
+ url("^(?P<user>\w+)/(?P<repo>\w+)/%s$" % f, ok_view) for f in features
+])
+
+# Total: 420 patterns
View
1  djangobench/benchmarks/url_resolve_nested/__init__.py
@@ -0,0 +1 @@
+
View
14 djangobench/benchmarks/url_resolve_nested/benchmark.py
@@ -0,0 +1,14 @@
+from django.core.urlresolvers import resolve, Resolver404
+from djangobench.utils import run_benchmark
+
+
+
+def benchmark():
+ resolve("/0/00/000/0000/00000/000000/0000000/00000000/leaf")
+
+run_benchmark(
+ benchmark,
+ meta = {
+ 'description': 'URL resolution with long-flat list of patterns.',
+ }
+)
View
4 djangobench/benchmarks/url_resolve_nested/settings.py
@@ -0,0 +1,4 @@
+from djangobench.base_settings import *
+
+INSTALLED_APPS = ['url_resolve_nested']
+ROOT_URLCONF = 'url_resolve_nested.urls'
View
30 djangobench/benchmarks/url_resolve_nested/urls.py
@@ -0,0 +1,30 @@
+from django.conf.urls.defaults import patterns, include, url
+import string
+
+def ok_view(request, *a, **kw):
+ pass
+
+def handler500(request):
+ pass
+
+leaf_patterns = patterns('', url(r"^leaf$", ok_view))
+
+def int2ascii(x, mod, alphabet=string.digits + string.ascii_letters):
+ alphabet = alphabet[:mod]
+ result = []
+ while x:
+ x, rem = divmod(x, mod)
+ result.append(alphabet[rem])
+ return (''.join(reversed(result))).rjust(1, alphabet[0])
+
+def pattern_tree(parent, height, level):
+ if height == 0:
+ return leaf_patterns
+ ids = [parent + int2ascii(i, level) for i in range(level)]
+ return patterns('',
+ *(url("^%s/" % id_, include(pattern_tree(id_, height-1, level)))
+ for id_ in ids)
+ )
+
+urlpatterns = pattern_tree("", 8, 2)
+# Total: 2**8 = 256 leafs, 511 nodes
Please sign in to comment.
Something went wrong with that request. Please try again.