Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Modified the middleware benchmarks to more accurately compare times.

  • Loading branch information...
commit 674ba7ca098f3d2ae9a8ce565e35be59bd021ff7 1 parent f5f1e0f
Jacob Kaplan-Moss jacobian authored
12 benchmarks/default_middleware/benchmark.py
View
@@ -3,6 +3,8 @@
from utils import run_benchmark
from django.test.client import Client
+from django.conf import global_settings
+from django.conf import settings
from django.core.handlers.wsgi import WSGIRequest
from django.core.handlers.wsgi import WSGIHandler
@@ -48,17 +50,23 @@ def request(self, **request):
return WSGIRequest(environ)
def benchmark():
-
req_factory = RequestFactory()
handler = WSGIHandler()
+
+ # Try first with Django's default middleware
+ settings.MIDDLEWARE_CLASSES = global_settings.MIDDLEWARE_CLASSES
handler.load_middleware()
with_middleware_time = time()
handler.get_response(req_factory.get('/'))
with_middleware_time = time() - with_middleware_time
+ # Now try the same process, but this time without any middleware.
+ settings.MIDDLEWARE_CLASSES = []
+ handler.load_middleware()
+
no_middleware_time = time()
- index(req_factory.get('/'))
+ handler.get_response(req_factory.get('/'))
no_middleware_time = time() - no_middleware_time
return with_middleware_time - no_middleware_time
7 benchmarks/default_middleware/settings.py
View
@@ -1,11 +1,4 @@
from base_settings import *
INSTALLED_APPS = ['default_middleware']
-MIDDLEWARE_CLASSES = (
- 'django.middleware.common.CommonMiddleware',
- 'django.contrib.sessions.middleware.SessionMiddleware',
- 'django.middleware.csrf.CsrfViewMiddleware',
- 'django.contrib.auth.middleware.AuthenticationMiddleware',
- 'django.contrib.messages.middleware.MessageMiddleware',
-)
ROOT_URLCONF = 'default_middleware.urls'
Please sign in to comment.
Something went wrong with that request. Please try again.