Skip to content

Instantly share code, notes, and snippets.

@tanner0101
Created June 13, 2016 02:56
Show Gist options
  • Save tanner0101/6d842b9be4b00de78074d2d1dc9426a2 to your computer and use it in GitHub Desktop.
Save tanner0101/6d842b9be4b00de78074d2d1dc9426a2 to your computer and use it in GitHub Desktop.
Django Benchmark
from django.conf.urls import url
from django.http import HttpResponse
from django.http import JsonResponse
from django.db import connection
def plaintext(request):
return HttpResponse('Hello, world')
def json(request):
return JsonResponse({
"array": [1, 2, 3],
"dict": {"one": 1, "two": 2, "three": 3},
"int": 42,
"string": "test",
"double": 3.14,
"null": None
})
def sqlite(request):
cursor = connection.cursor()
cursor.execute("SELECT * FROM users ORDER BY random() LIMIT 1")
row = cursor.fetchone()
return JsonResponse(row, safe=False)
urlpatterns = [
url(r'^plaintext', plaintext),
url(r'^json', json),
url(r'^sqlite-fetch', sqlite)
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment