alexmic/microtemplates — pull request #1 by ambv (2013-04-12 15:04:46+00:00)
Title: Benchmark production-grade ways of loading templates in Django and Jinja2

Hey there!
Cool research project, good job. However, your benchmarks used some unrealistic ways of loading templates for Django and Jinja2. To make the comparison more apples-to-apples, I added some commonly used ways to load templates to `benchmarks.py`. Specifically:

* using Django's default template loader
* using Django's recommended caching loader
* using Jinja's `Environment` object

I also moved the file reading part away from other benchmarks so that we don't measure the speed of your storage.

The benchmarks with those are as follows on my machine:

```
microtemplates => run 10000 times, took 0.36 ms
django => run 10000 times, took 0.95 ms
django_default_loader => run 10000 times, took 1.16 ms
django_cached_loader => run 10000 times, took 0.46 ms
jinja2 => run 10000 times, took 5.64 ms
jinja2_env => run 10000 times, took 0.08 ms
```

Here, note the following: `microtemplates` are still faster than Django's cached loader, congratulations! The margin is much smaller, though. In case of Jinja2, the reason why your original method is so slow is that the data structures being built are optimized towards later reuse. Also in terms of generating helpful tracebacks when something in the template is actually wrong.