This commit is contained in:
Will Abbott 2024-06-23 19:12:07 +01:00
parent 55c060e6e1
commit bbeb5081c7
6 changed files with 195 additions and 105 deletions

View file

@ -133,4 +133,4 @@ STATIC_URL = "static/"
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
COTTON_TEMPLATE_CACHING_ENABLED = False
# COTTON_TEMPLATE_CACHING_ENABLED = False

View file

@ -1,9 +1,9 @@
{% cotton_component cotton/benchmarks/partials/main.cotton.html %}
{% cotton_component cotton/benchmarks/partials/main.cotton.html test_key %}
I'm default
{% cotton_slot top %}
{% cotton_slot top test_key %}
I'm top
{% end_cotton_slot %}
{% cotton_slot bottom %}
{% cotton_slot bottom test_key %}
I'm bottom
{% end_cotton_slot %}
{% end_cotton_component %}

View file

@ -1,7 +1,8 @@
from django.conf import settings
import time
from django.template.loader import render_to_string
import django
from django.conf import settings
from django.template.loader import render_to_string
# Configure Django settings
settings.configure(
@ -38,6 +39,8 @@ settings.configure(
},
},
],
# Toggle this to turn caching on and off
COTTON_TEMPLATE_CACHING_ENABLED=True,
)
django.setup()
@ -55,7 +58,6 @@ def benchmark_template_rendering(template_name, iterations=1000):
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"
)
@ -63,9 +65,7 @@ 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")