Blitz for PHP

By Deane Barker on August 14, 2007

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:

  1. Smarty is much more mature. There’s a stronger feature set and a lot more support available.

  2. 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.

Gadgetopia

Comments

  1. Well speaking as a developer of the PHPulse framework, the world’s fastest (yes, no one has beaten our benchmarks yet), we try to look at every tiny aspect to squeeze every split second we can. The more of those split seconds you can squeeze, they all add up to seconds. In a benchmark of ‘ab -n10000 -c1000’ on a 1.4ghz machine, PHPulse can do 471 requests per seconds… on average.

    I’m strongly considering moving to Blitz so I can start getting this over 600 requests per second.

  2. I’m strongly considering moving to Blitz so I can start getting this over 600 requests per second.

    Make it optional. Blitz involves installing a compiled extension to your PHP install, which out of reach for most people on hosted accounts.

    You seem obsessed with your RPS number. Putting your framework out of reach for most people just to bump that number higher will do more harm than good.

  3. Not everyone should be striving for speed – but someone should, be it just to set the frame and demonstrate the consequences. So please, Owen and phpulse workers, continue the good work!

Comments are closed. If you have something you really want to say, email editors@gadgetopia.com and we‘ll get it added for you.