diff --git a/dev/example_project/example_project/templates/child_test.html b/dev/example_project/example_project/templates/child_test.html
deleted file mode 100644
index ec03be8..0000000
--- a/dev/example_project/example_project/templates/child_test.html
+++ /dev/null
@@ -1,3 +0,0 @@
-
- d
-
\ No newline at end of file
diff --git a/dev/example_project/example_project/templates/cotton/benchmarks/cotton.html b/dev/example_project/example_project/templates/cotton/benchmarks/cotton_extends_equivalent.html
similarity index 100%
rename from dev/example_project/example_project/templates/cotton/benchmarks/cotton.html
rename to dev/example_project/example_project/templates/cotton/benchmarks/cotton_extends_equivalent.html
index 57996ab..e133dfa 100644
--- a/dev/example_project/example_project/templates/cotton/benchmarks/cotton.html
+++ b/dev/example_project/example_project/templates/cotton/benchmarks/cotton_extends_equivalent.html
@@ -1,8 +1,8 @@
- I'm default
I'm top
+ I'm default
I'm bottom
diff --git a/dev/example_project/example_project/templates/cotton/child.html b/dev/example_project/example_project/templates/cotton/child.html
deleted file mode 100644
index 9f989fa..0000000
--- a/dev/example_project/example_project/templates/cotton/child.html
+++ /dev/null
@@ -1 +0,0 @@
-
\ No newline at end of file
diff --git a/dev/example_project/example_project/templates/cotton/named_slot_component.html b/dev/example_project/example_project/templates/cotton/named_slot_component.html
deleted file mode 100644
index e324e2c..0000000
--- a/dev/example_project/example_project/templates/cotton/named_slot_component.html
+++ /dev/null
@@ -1,3 +0,0 @@
-
- {{ name }}
-
\ No newline at end of file
diff --git a/dev/example_project/example_project/templates/cotton/parent.html b/dev/example_project/example_project/templates/cotton/parent.html
deleted file mode 100644
index ccf4342..0000000
--- a/dev/example_project/example_project/templates/cotton/parent.html
+++ /dev/null
@@ -1,3 +0,0 @@
-
- {{ slot }}
-
\ No newline at end of file
diff --git a/dev/example_project/example_project/templates/cotton/vars_test_component.html b/dev/example_project/example_project/templates/cotton/vars_test_component.html
deleted file mode 100644
index f7a1a50..0000000
--- a/dev/example_project/example_project/templates/cotton/vars_test_component.html
+++ /dev/null
@@ -1,12 +0,0 @@
-
-
-
- {{ testy }}
-
var1: '{{ var1 }}'
-
attr1: '{{ attr1 }}'
-
empty_var: '{{ empty_var }}'
-
var_with_default: '{{ var_with_default }}'
-
slot: '{{ slot }}'
-
named_slot: '{{ named_slot }}'
-
attrs: '{{ attrs }}'
-
diff --git a/dev/example_project/example_project/templates/form_test.html b/dev/example_project/example_project/templates/form_test.html
deleted file mode 100644
index 6c70273..0000000
--- a/dev/example_project/example_project/templates/form_test.html
+++ /dev/null
@@ -1,3 +0,0 @@
-
-
-
\ No newline at end of file
diff --git a/dev/example_project/example_project/templates/index.html b/dev/example_project/example_project/templates/index.html
deleted file mode 100644
index be843b5..0000000
--- a/dev/example_project/example_project/templates/index.html
+++ /dev/null
@@ -1,3 +0,0 @@
-{% for i in '123456789' %}
-
-{% endfor %}
\ No newline at end of file
diff --git a/dev/example_project/example_project/templates/named_slot_in_loop.html b/dev/example_project/example_project/templates/named_slot_in_loop.html
deleted file mode 100644
index 136d7c1..0000000
--- a/dev/example_project/example_project/templates/named_slot_in_loop.html
+++ /dev/null
@@ -1,7 +0,0 @@
-{% for item in items %}
-
-
- item name: {{ item.name }}
-
-
-{% endfor %}
\ No newline at end of file
diff --git a/dev/example_project/example_project/templates/parent_test.html b/dev/example_project/example_project/templates/parent_test.html
deleted file mode 100644
index 9922300..0000000
--- a/dev/example_project/example_project/templates/parent_test.html
+++ /dev/null
@@ -1 +0,0 @@
-
\ No newline at end of file
diff --git a/dev/example_project/example_project/templates/self_closing_test.html b/dev/example_project/example_project/templates/self_closing_test.html
deleted file mode 100644
index 9c99f37..0000000
--- a/dev/example_project/example_project/templates/self_closing_test.html
+++ /dev/null
@@ -1,4 +0,0 @@
-{% load static %}
-
-
-
\ No newline at end of file
diff --git a/dev/example_project/example_project/templates/simple_cotton.html b/dev/example_project/example_project/templates/simple_cotton.html
index 911b49a..d3e9873 100644
--- a/dev/example_project/example_project/templates/simple_cotton.html
+++ b/dev/example_project/example_project/templates/simple_cotton.html
@@ -1 +1 @@
-{% for d in data %}{% endfor %}
\ No newline at end of file
+{% for d in data %}{% endfor %}
\ No newline at end of file
diff --git a/dev/example_project/example_project/templates/simple_native.html b/dev/example_project/example_project/templates/simple_native.html
index 615d7e9..d3d6655 100644
--- a/dev/example_project/example_project/templates/simple_native.html
+++ b/dev/example_project/example_project/templates/simple_native.html
@@ -1 +1 @@
-{% for d in data %}
{{ d }}
{% endfor %}
+{% for d in data %}
{% include 'benchmarks/native_include.html' %}
{% endfor %}
diff --git a/dev/example_project/example_project/templates/vars_test.html b/dev/example_project/example_project/templates/vars_test.html
deleted file mode 100644
index 9f16cca..0000000
--- a/dev/example_project/example_project/templates/vars_test.html
+++ /dev/null
@@ -1,3 +0,0 @@
-
- default slot
-
\ No newline at end of file
diff --git a/dev/example_project/render_load_test.py b/dev/example_project/render_load_test.py
index 98f6846..232f75f 100644
--- a/dev/example_project/render_load_test.py
+++ b/dev/example_project/render_load_test.py
@@ -19,8 +19,18 @@ settings.configure(
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": ["example_project/templates"],
- "APP_DIRS": False,
+ "APP_DIRS": True,
"OPTIONS": {
+ "loaders": [
+ (
+ "django.template.loaders.cached.Loader",
+ [
+ "django_cotton.loader.CottonLoader",
+ "django.template.loaders.filesystem.Loader",
+ "django.template.loaders.app_directories.Loader",
+ ],
+ )
+ ],
"context_processors": [
"django.template.context_processors.debug",
"django.template.context_processors.request",
@@ -37,38 +47,59 @@ settings.configure(
django.setup()
-def template_bench(template_name, iterations=500):
+def template_bench(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)
+ duration = round((end_time - start_time) * 1000, 2)
+
+ return duration, render_to_string(template_name)
-def template_bench_alt(template_name, iterations=500):
+def template_bench_alt(template_name, iterations=1000):
data = list(range(1, iterations))
start_time = time.time()
render_to_string(template_name, context={"data": data})
end_time = time.time()
- return end_time - start_time, render_to_string(template_name)
+ duration = round((end_time - start_time) * 1000, 2)
+ return duration, render_to_string(template_name)
+
+
+# warm caches
+template_bench_alt("simple_native.html", iterations=1)
+template_bench_alt("simple_cotton.html", iterations=1)
simple_native, _ = template_bench_alt("simple_native.html")
simple_cotton, _ = template_bench_alt("simple_cotton.html")
-print(f"Native Django Template: {simple_native} seconds")
-print(f"Cotton Template: {simple_cotton} seconds")
+print("---")
+print(f"Native Django {{% for %}} loop: {simple_native} ms")
+print(f"Cotton {{% for %}} loop: {simple_cotton} ms")
+
+# warm caches
+template_bench("benchmarks/native_include.html", iterations=1)
+template_bench("cotton/benchmarks/cotton_include.html", iterations=1)
time_native_include, _ = template_bench("benchmarks/native_include.html")
time_cotton_include, _ = template_bench("cotton/benchmarks/cotton_include.html")
-print(f"Native {{% include %}}: {time_native_include} seconds")
-print(f"Cotton for include:: {time_cotton_include} seconds")
+print("---")
+print(f"Native {{% include %}}: {time_native_include} ms")
+print(f"Cotton for include: {time_cotton_include} ms")
+
+# warm caches
+template_bench("benchmarks/native_extends.html", iterations=1)
+template_bench("cotton/benchmarks/cotton_compiled.html", iterations=1)
+template_bench("cotton/benchmarks/cotton_extends_equivalent.html", iterations=1)
time_native_extends, _ = template_bench("benchmarks/native_extends.html")
time_compiled_cotton, _ = template_bench("cotton/benchmarks/cotton_compiled.html")
-time_cotton, _ = template_bench("cotton/benchmarks/cotton.html")
+time_cotton, _ = template_bench("cotton/benchmarks/cotton_extends_equivalent.html")
-print(f"Native {{% block %}} and {{% extends %}}: {time_native_extends} seconds")
-print(f"Uncompiled Cotton Template: {time_cotton} seconds")
-print(f"Compiled Cotton Template: {time_compiled_cotton} seconds")
+
+print("---")
+print(f"Native {{% block %}} and {{% extends %}}: {time_native_extends} ms")
+print(f"Compiled Cotton Template: {time_compiled_cotton} ms")
+print(f"Uncompiled Cotton Template: {time_cotton} ms")
diff --git a/dev/example_project/unspecified_app_directory/templates/cotton/app_outside_of_dirs.html b/dev/example_project/unspecified_app_directory/templates/cotton/app_outside_of_dirs.html
new file mode 100644
index 0000000..ad1ba63
--- /dev/null
+++ b/dev/example_project/unspecified_app_directory/templates/cotton/app_outside_of_dirs.html
@@ -0,0 +1 @@
+My template path was not specified in settings!
\ No newline at end of file
diff --git a/dev/example_project/unspecified_app_directory/templates/cotton/unspecified_component.html b/dev/example_project/unspecified_app_directory/templates/cotton/unspecified_component.html
deleted file mode 100644
index 51f8237..0000000
--- a/dev/example_project/unspecified_app_directory/templates/cotton/unspecified_component.html
+++ /dev/null
@@ -1 +0,0 @@
-My template was not specified in settings!
\ No newline at end of file
diff --git a/dev/example_project/unspecified_app_directory/templates/unspecified_view.html b/dev/example_project/unspecified_app_directory/templates/unspecified_view.html
deleted file mode 100644
index 12b3ec5..0000000
--- a/dev/example_project/unspecified_app_directory/templates/unspecified_view.html
+++ /dev/null
@@ -1 +0,0 @@
-
\ No newline at end of file
diff --git a/django_cotton/templates/attribute_merging_test.html b/django_cotton/templates/attribute_merging_test.html
deleted file mode 100644
index ebcf664..0000000
--- a/django_cotton/templates/attribute_merging_test.html
+++ /dev/null
@@ -1,3 +0,0 @@
-
- ss
-
\ No newline at end of file
diff --git a/django_cotton/templates/attribute_passing_test.html b/django_cotton/templates/attribute_passing_test.html
deleted file mode 100644
index a7bc9fc..0000000
--- a/django_cotton/templates/attribute_passing_test.html
+++ /dev/null
@@ -1,3 +0,0 @@
-
- ss
-
\ No newline at end of file
diff --git a/django_cotton/templates/child_test.html b/django_cotton/templates/child_test.html
deleted file mode 100644
index ec03be8..0000000
--- a/django_cotton/templates/child_test.html
+++ /dev/null
@@ -1,3 +0,0 @@
-
- d
-
\ No newline at end of file
diff --git a/django_cotton/templates/cotton/child.html b/django_cotton/templates/cotton/child.html
deleted file mode 100644
index 9f989fa..0000000
--- a/django_cotton/templates/cotton/child.html
+++ /dev/null
@@ -1 +0,0 @@
-
\ No newline at end of file
diff --git a/django_cotton/templates/cotton/container.html b/django_cotton/templates/cotton/container.html
deleted file mode 100644
index 835e5c4..0000000
--- a/django_cotton/templates/cotton/container.html
+++ /dev/null
@@ -1,11 +0,0 @@
-
- Header:
- {{ header }}
-
-
-
- Content:
- {{ slot }}
-
-
-
diff --git a/django_cotton/templates/cotton/eval_attributes_test_component.html b/django_cotton/templates/cotton/eval_attributes_test_component.html
deleted file mode 100644
index f84dbe3..0000000
--- a/django_cotton/templates/cotton/eval_attributes_test_component.html
+++ /dev/null
@@ -1,27 +0,0 @@
-{% if none is None %}
-