added amits tests

This commit is contained in:
Will Abbott 2024-07-09 21:34:38 +01:00
parent 074c177563
commit a035130dfc
4 changed files with 43 additions and 25 deletions

View file

@ -54,31 +54,46 @@ def benchmark_template_rendering(template_name, iterations=10000):
return end_time - start_time, render_to_string(template_name)
# Benchmarking each template
time_native_include, output_native_include = benchmark_template_rendering(
"benchmarks/native_include.html"
)
time_cotton_include, output_cotton_include = benchmark_template_rendering(
"cotton/benchmarks/cotton_include.html"
)
def benchmark_template_rendering_alt(template_name, iterations=10000):
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)
time_native_extends, output_native_extends = benchmark_template_rendering(
"benchmarks/native_extends.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.html"
)
simple_native = benchmark_template_rendering_alt("simple_native.html")
simple_cotton = benchmark_template_rendering_alt("simple_cotton.html")
# Output results
print("Include, native vs cotton:")
print(f"Native {{% include %}}: {time_native_include} seconds")
print(f"Cotton for include:: {time_cotton_include} seconds")
print("-------")
print("Block + Extends, native vs cotton:")
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(f"Native Django Template: {simple_native} seconds")
print(f"Cotton Template: {simple_cotton} seconds")
#
# # Benchmarking each template
# time_native_include, output_native_include = benchmark_template_rendering(
# "benchmarks/native_include.html"
# )
# time_cotton_include, output_cotton_include = benchmark_template_rendering(
# "cotton/benchmarks/cotton_include.html"
# )
#
#
# time_native_extends, output_native_extends = benchmark_template_rendering(
# "benchmarks/native_extends.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.html"
# )
#
# # Output results
# print("Include, native vs cotton:")
# print(f"Native {{% include %}}: {time_native_include} seconds")
# print(f"Cotton for include:: {time_cotton_include} seconds")
# print("-------")
# print("Block + Extends, native vs cotton:")
# 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")