From d8478404287e921b8404f14606d4226832da4a29 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Wed, 21 Aug 2024 15:54:52 +0100 Subject: [PATCH 1/2] Add URL benchmarks for `path` URLs --- benchmarks/url_benchmarks/url_resolve/benchmark.py | 6 ++++++ benchmarks/url_benchmarks/url_resolve/urls.py | 4 +++- benchmarks/url_benchmarks/url_reverse/benchmark.py | 7 +++++++ benchmarks/url_benchmarks/url_reverse/urls.py | 4 +++- 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/benchmarks/url_benchmarks/url_resolve/benchmark.py b/benchmarks/url_benchmarks/url_resolve/benchmark.py index 7d5b6b6d74..9652bd1c84 100644 --- a/benchmarks/url_benchmarks/url_resolve/benchmark.py +++ b/benchmarks/url_benchmarks/url_resolve/benchmark.py @@ -12,3 +12,9 @@ def time_resolve(self): resolve("/url-resolve/basic/") resolve("/url-resolve/fallthroughview/") resolve("/url-resolve/replace/1") + + def time_resolve_path(self): + resolve("/url-resolve/num/1/") + + def time_resolve_literal_path(self): + resolve("/url-resolve/basic-path/") diff --git a/benchmarks/url_benchmarks/url_resolve/urls.py b/benchmarks/url_benchmarks/url_resolve/urls.py index 764f42bf5f..60791ffa95 100644 --- a/benchmarks/url_benchmarks/url_resolve/urls.py +++ b/benchmarks/url_benchmarks/url_resolve/urls.py @@ -1,4 +1,4 @@ -from django.urls import re_path +from django.urls import path, re_path from . import views @@ -13,3 +13,5 @@ def generate_filler_patterns(num=1): urlpatterns.append(re_path(r"^basic/$", views.basic, name="basic")) urlpatterns.append(re_path(r"^[a-z]*/$", views.catchall, name="catchall")) urlpatterns.append(re_path(r"^replace/(?P.*?)", views.vars, name="vars")) +urlpatterns.append(path("num//", views.vars, name="num")) +urlpatterns.append(path("basic-path/", views.vars, name="basic-path")) diff --git a/benchmarks/url_benchmarks/url_reverse/benchmark.py b/benchmarks/url_benchmarks/url_reverse/benchmark.py index 6c02bc9124..e91da34902 100644 --- a/benchmarks/url_benchmarks/url_reverse/benchmark.py +++ b/benchmarks/url_benchmarks/url_reverse/benchmark.py @@ -12,3 +12,10 @@ def time_reverse(self): reverse("url_reverse:catchall") reverse("url_reverse:vars", args=[1]) reverse("url_reverse:vars", kwargs={"var": 1}) + + def time_reverse_path(self): + reverse("url_reverse:num", args=[1]) + reverse("url_reverse:num", kwargs={"var": 1}) + + def time_reverse_literal_path(self): + reverse("url_reverse:basic-path") diff --git a/benchmarks/url_benchmarks/url_reverse/urls.py b/benchmarks/url_benchmarks/url_reverse/urls.py index d4423be679..908d1bac2f 100644 --- a/benchmarks/url_benchmarks/url_reverse/urls.py +++ b/benchmarks/url_benchmarks/url_reverse/urls.py @@ -1,4 +1,4 @@ -from django.urls import re_path +from django.urls import path, re_path from . import views @@ -15,3 +15,5 @@ def generate_filler_patterns(num=1): urlpatterns.append(re_path(r"^basic/$", views.basic, name="basic")) urlpatterns.append(re_path(r"^[a-z]*/$", views.catchall, name="catchall")) urlpatterns.append(re_path(r"^replace/(?P.*?)", views.vars, name="vars")) +urlpatterns.append(path("num//", views.vars, name="num")) +urlpatterns.append(path("basic-path/", views.vars, name="basic-path")) From c51ad5e5a87625f5ebdc554b48ab71edd83da9da Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Wed, 21 Aug 2024 15:59:58 +0100 Subject: [PATCH 2/2] Add benchmark for resolver errors --- benchmarks/url_benchmarks/url_resolve/benchmark.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/benchmarks/url_benchmarks/url_resolve/benchmark.py b/benchmarks/url_benchmarks/url_resolve/benchmark.py index 9652bd1c84..d1fed4aef7 100644 --- a/benchmarks/url_benchmarks/url_resolve/benchmark.py +++ b/benchmarks/url_benchmarks/url_resolve/benchmark.py @@ -1,4 +1,4 @@ -from django.urls import resolve +from django.urls import resolve, Resolver404 from ...utils import bench_setup @@ -18,3 +18,9 @@ def time_resolve_path(self): def time_resolve_literal_path(self): resolve("/url-resolve/basic-path/") + + def time_resolve_unknown(self): + try: + resolve("/unknown/") + except Resolver404: + pass