mirror of
https://github.com/wrabit/django-cotton.git
synced 2025-07-24 18:03:46 +00:00
first release
This commit is contained in:
parent
c38c990b5b
commit
4c4d00d4df
2269 changed files with 323498 additions and 2 deletions
71
dev/example_project/render_load_test.py
Normal file
71
dev/example_project/render_load_test.py
Normal file
|
@ -0,0 +1,71 @@
|
|||
from django.conf import settings
|
||||
import time
|
||||
from django.template.loader import render_to_string
|
||||
import django
|
||||
|
||||
# Configure Django settings
|
||||
settings.configure(
|
||||
INSTALLED_APPS=[
|
||||
"django.contrib.admin",
|
||||
"django.contrib.auth",
|
||||
"django.contrib.contenttypes",
|
||||
"django.contrib.sessions",
|
||||
"django.contrib.messages",
|
||||
"django.contrib.staticfiles",
|
||||
"django_cotton",
|
||||
],
|
||||
TEMPLATES=[
|
||||
{
|
||||
"BACKEND": "django.template.backends.django.DjangoTemplates",
|
||||
"DIRS": ["example_project/templates"],
|
||||
"APP_DIRS": False,
|
||||
"OPTIONS": {
|
||||
"context_processors": [
|
||||
"django.template.context_processors.debug",
|
||||
"django.template.context_processors.request",
|
||||
"django.contrib.auth.context_processors.auth",
|
||||
"django.contrib.messages.context_processors.messages",
|
||||
],
|
||||
"loaders": [
|
||||
"django_cotton.cotton_loader.Loader",
|
||||
"django.template.loaders.filesystem.Loader",
|
||||
"django.template.loaders.app_directories.Loader",
|
||||
],
|
||||
"builtins": [
|
||||
"django.templatetags.static",
|
||||
"django_cotton.templatetags.cotton",
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
)
|
||||
|
||||
django.setup()
|
||||
|
||||
|
||||
def benchmark_template_rendering(template_name, iterations=1000):
|
||||
start_time = time.time()
|
||||
for _ in range(iterations):
|
||||
render_to_string(template_name)
|
||||
end_time = time.time()
|
||||
return end_time - start_time, render_to_string(template_name)
|
||||
|
||||
|
||||
# Benchmarking each template
|
||||
time_native_extends, output_native_extends = benchmark_template_rendering(
|
||||
"cotton/benchmarks/native_extends.html"
|
||||
)
|
||||
# time_native_include, output_native_include = benchmark_template_rendering('cotton/benchmarks/native_include.html')
|
||||
time_compiled_cotton, output_compiled_cotton = benchmark_template_rendering(
|
||||
"cotton/benchmarks/cotton_compiled.html"
|
||||
)
|
||||
time_cotton, output_cotton = benchmark_template_rendering(
|
||||
"cotton/benchmarks/cotton.cotton.html"
|
||||
)
|
||||
|
||||
|
||||
# Output results
|
||||
print(f"Native Django Template using extend: {time_native_extends} seconds")
|
||||
# print(f"Native Django Template using include: {time_native_include} seconds")
|
||||
print(f"Compiled Cotton Template: {time_compiled_cotton} seconds")
|
||||
print(f"Cotton Template: {time_cotton} seconds")
|
Loading…
Add table
Add a link
Reference in a new issue