Django template performance

What is more efficient in Django: rendering an object using a template language? or click code to render an object using templatetag function using python language?

+4
source share
3 answers

The question is something like a meaningless one. Templates will always be slower than a manually configured rendering solution, but template tags should still go through the Template mechanism, so you lose any advantage there. If you want super-high performance, consider writing all HTML as an array of Python strings, concatenate () them once, and then pass your HTML back as the body of an HTTPResponse object.

Or you can try all three and profile them. Since we do not know your code, we will not be able to work with you. After several experiments, you should be satisfied with which approach suits you.

Template engine is almost never your bottleneck. Your database is the most likely bottleneck. You have a Django toolbar, right? If the template system has no performance issues, always use the solution that will be the cheapest for you.

+3
source

This is similar to the argument about the most efficient way to add strings (almost every programming language has this argument). This is 2011, not 1970. Even consumer-level computers have the computing power and memory to match supercomputers of the last decade. Network server class machines have much more. Saving a loop or two processors these days is pretty pointless. It is one thing when you develop the system code of the OS or low-level system processes, but you lose time parsing the template.

+3
source

I would say this in much the same way; take the cleanest way, and if you need speed, cache it.

+1
source

All Articles