| 1 | from collections import namedtuple
|
|---|
| 2 |
|
|---|
| 3 | from django.utils.functional import SimpleLazyObject
|
|---|
| 4 |
|
|---|
| 5 | import os
|
|---|
| 6 | from django.conf import settings
|
|---|
| 7 | import django
|
|---|
| 8 | from django.template import Template, Context
|
|---|
| 9 |
|
|---|
| 10 | ROOT = os.path.dirname(django.__file__)
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 | def urls():
|
|---|
| 14 | from django.urls import path
|
|---|
| 15 | from django.contrib import admin
|
|---|
| 16 |
|
|---|
| 17 | return (path("admin", admin.site.urls),)
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 | settings.configure(
|
|---|
| 21 | DEBUG=False,
|
|---|
| 22 | INSTALLED_APPS=(
|
|---|
| 23 | "django.contrib.contenttypes",
|
|---|
| 24 | "django.contrib.auth",
|
|---|
| 25 | "django.contrib.admin",
|
|---|
| 26 | ),
|
|---|
| 27 | ROOT_URLCONF=SimpleLazyObject(urls),
|
|---|
| 28 | TEMPLATES=[
|
|---|
| 29 | {
|
|---|
| 30 | "BACKEND": "django.template.backends.django.DjangoTemplates",
|
|---|
| 31 | "DIRS": [],
|
|---|
| 32 | "APP_DIRS": True,
|
|---|
| 33 | "OPTIONS": {
|
|---|
| 34 | "context_processors": [
|
|---|
| 35 | "django.template.context_processors.request",
|
|---|
| 36 | "django.contrib.auth.context_processors.auth",
|
|---|
| 37 | "django.contrib.messages.context_processors.messages",
|
|---|
| 38 | ],
|
|---|
| 39 | },
|
|---|
| 40 | },
|
|---|
| 41 | ],
|
|---|
| 42 | )
|
|---|
| 43 | django.setup()
|
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 | changelist_path = os.path.join(
|
|---|
| 47 | ROOT, "contrib", "admin", "templates", "admin", "change_list.html"
|
|---|
| 48 | )
|
|---|
| 49 | with open(changelist_path, "r") as f:
|
|---|
| 50 | changelist = f.read()
|
|---|
| 51 |
|
|---|
| 52 | t = Template(changelist)
|
|---|
| 53 | fakeopts = namedtuple("Opts", "app_label object_name")("auth", "user")
|
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 | class ChangeList:
|
|---|
| 57 | result_count = 0
|
|---|
| 58 | full_result_count = 0
|
|---|
| 59 | opts = fakeopts
|
|---|
| 60 | list_display = ()
|
|---|
| 61 | formset = None
|
|---|
| 62 | result_list = ()
|
|---|
| 63 | show_all = False
|
|---|
| 64 | multi_page = False
|
|---|
| 65 | can_show_all = True
|
|---|
| 66 |
|
|---|
| 67 | def get_ordering_field_columns(self):
|
|---|
| 68 | return []
|
|---|
| 69 |
|
|---|
| 70 |
|
|---|
| 71 | ctx = Context({"cl": ChangeList(), "opts": fakeopts})
|
|---|
| 72 |
|
|---|
| 73 |
|
|---|
| 74 | def yappi():
|
|---|
| 75 | import yappi as pr
|
|---|
| 76 |
|
|---|
| 77 | pr.start()
|
|---|
| 78 |
|
|---|
| 79 | for x in range(1_000):
|
|---|
| 80 | t.render(ctx)
|
|---|
| 81 |
|
|---|
| 82 | pr.stop()
|
|---|
| 83 | pr.get_func_stats().print_all()
|
|---|
| 84 |
|
|---|
| 85 |
|
|---|
| 86 | def cprofile():
|
|---|
| 87 | import cProfile as profiler
|
|---|
| 88 |
|
|---|
| 89 | pr = profiler.Profile()
|
|---|
| 90 | pr.enable()
|
|---|
| 91 |
|
|---|
| 92 | for x in range(1_000):
|
|---|
| 93 | t.render(ctx)
|
|---|
| 94 |
|
|---|
| 95 | pr.disable()
|
|---|
| 96 | pr.print_stats()
|
|---|
| 97 |
|
|---|
| 98 |
|
|---|
| 99 | def timeonly():
|
|---|
| 100 | for x in range(1_000):
|
|---|
| 101 | t.render(ctx)
|
|---|
| 102 |
|
|---|
| 103 |
|
|---|
| 104 | if __name__ == "__main__":
|
|---|
| 105 | # For checking walltime via CLI `time python ...`
|
|---|
| 106 | for x in range(1_000):
|
|---|
| 107 | t.render(ctx)
|
|---|