Working on a profiling/benchmark tool for the django template language. Looking for feedback on my work so far.

70 views
Skip to first unread message

Quentin Fulsher

unread,
Mar 19, 2016, 8:41:33 AM3/19/16
to Django developers (Contributions to Django itself)
Hi all, I talked with FunkyBob on IRC a few weeks ago and told him I was interested in optimizing the template language. One of the suggestions he made was to make a profiling/benchmarking framework to test changes. While I wouldn't call it a framework yet I have a script set up to run the django template language on a few simple templates and profile individual functions. Right now I have the render(), context(), and Template() methods added but definitely plan on adding more. You can read more on the github page to learn the exact commands but the script can run individual test cases and print out a pstats log. By specifying -o you can also create a callgraph. 

At this point I'm looking for ways to improve. Right now the script implementation is kinda messy.

https://github.com/inondle/django-template-benchmark


The main thing I want to improve is the way that test cases are run and implemented. To add a test case in this implementation you would have to:

  • Write a function and decorate it with @cprofile

  • Create a new elif statement at the bottom and check for a keyword

  • Run the script with -t <KEYWORD>

While this isn't a terrible work flow it leaves a lot to be desired. I would like to make it more like how the unittest module works with a setup and test method but rather than checking assertions it just profiles the code and prints out a pstats log for each test case. The pstats log can then be rendered further into a call graph or something else. 


I've tried to build a profiler class which uses method introspection to run tests but it gets really complicated really fast. I've looked online and can't find a way to subclass or extend the unittest module to do this. Is there a way that I could get the feel of a unittest module but for profiling code instead of running unit tests?


I also need to improve the templates that I run. Right now they are very simple and only render a few lines with a pretty minimal context. If anyone has suggestions on test templates I'm all ears.

Tim Graham

unread,
Mar 22, 2016, 8:52:49 AM3/22/16
to Django developers (Contributions to Django itself)
Did FunkyBob indicate he was interested in mentoring this project? In my view, the idea isn't so important now that we have Jinja2 integration but I didn't remove it from the idea list since I didn't get a definitive answer about that.
Reply all
Reply to author
Forward
0 new messages