l love Smarty, the PHP templating engine. It makes presentation development a lot simpler and more pleasant.
However, there’s always a guilt factor involved, because whenever you introduce an abstraction, you introduce processing overhead. Smarty is written in pure PHP, so there’s extra processing post-parse, which will always slow things down.
Enter Blitz. It’s a PHP templating library written in C and distributed as a compiled PHP extension. As such, it’s awfully fast. The official page has a bunch of benchmarks, but this article subjects Blitz to some real-world tests and compares it to Smarty and native PHP file includes. The results:
Blitz won two of the three tests and came in a close second in the last [to native PHP]. Of course, one could argue that PHP “won” the first test since there was no need to be tested on instantiation.
Considering the short amount of time Blitz has been under active development, its sheer speed is rather amazing.
I’ll admit that it’s impressive. A complex template requiring 10,000 iterations of something was generated by Blitz in .07 seconds. In all the tests, Smarty came in between 30% and 50% slower than Blitz. In fact, Blitz was awfully close to native PHP in most cases.
Now, to be fair, let’s note a couple things:
Smarty is much more mature. There’s a stronger feature set and a lot more support available.
For most applications, we’re splitting hairs. I know I said “30% and 50% slower,” but in reality, this is the different between .0001 seconds and .006 seconds for a simple template. Let’s be honest: I don’t think I’ve written an app where 59 ten-thousands of a second was going to change much. However, I know these apps exist, so there’s certainly a place for this.
Of course, the “extra processing” argument against Smarty has been raised before. Savant is a PHP templating engine that uses PHP as its actual language. Gosh, how quaint.