Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Google Sign In with OpenID

Benchmarks: Elefant templates vs Twig vs Smarty 3

edited June 2012 in Framework

I just put together a simple benchmark of Elefant's template engine against the popular Twig template engine. Here are the results:

Wanted to start benchmarking other areas of the framework than just simple Hello World's :)


  • Nice results...and nice specs on the Mac. Which one you have?

  • It's an 21.5" iMac, 2010 or 2011 I believe. It's what I use at work, but since I put an SSD drive in my home machine (mid 2010 MBP) it's feeling less cool now... :)

  • Any idea why such the massive difference? Elefant benchmarks so insanely well against almost everything else, it makes me really curious why?

    Reading through the code I understand there is A LOT less overhead in Elefant because of some of the techniques you used but it just boggles my mind how much raw performance you can get with what seems to be very little drop in usability from the developers end.

  • In the hello world benchmarks, I expected to be slower than that, and I wonder if it's something as simple as gzip vs none.

    In this case, I think what a lot of developers are doing is applying patterns that just don't make sense in scripts that run once and exit. They make more sense in longer-running applications like Java frameworks or Rails, but in PHP it just adds unnecessary memory overhead since it's compounded by each request.

    That's not a very popular way of thinking in the PHP world at the moment, but for me, being able to serve twice as many visitors before worrying about scaling my web servers (and serving them in ~10-20ms execution time) is pretty sweet :)

  • I have a mid 2007 MBP with 3 gigs of ram...less than 2 hours of typing on it. It stays connected to an external keyboard and mouse and 2 22" screens. Been powered up 24/7 since I purchased it. Still works great but thinking about getting a true desktop. Still have a G5 with 500GB drives but thats running Ubuntu 10.10 and is hosting about 20 websites including 2 streaming media sites as well as wordpress and elefantcms and others. Got a big boy dell poweredge server as my other webserver too. I have a block of statics at home so its pretty convenient.

  • Seems pretty speedy and I am also just a bit concerned to why?

    Are there any benchmarks against something like Smarty 3? This seems to be a bit slower compiling, but quite quick after that? (Source:

    Of course it is difficult to know what metric to use, time to compile, speed after compile, memory usage...

  • I just added Smarty 3 to the mix and updated the results. I also added another test to measure the overall memory usage of initializing each template engine and added those to the bottom of the results. Smarty 3 is definitely faster than Twig, but I'm happy to see Elefant still manages to edge it out :)

    The why of it is that Elefant's template engine is very simple. It compiles patterns to raw PHP (with output sanitizing added by default), then includes the compiled PHP. Since it's all based on regex matching, the compiler never sees the data itself, so it can't introduce security issues in the generated PHP by eval()-ing data.

    The one thing Smarty beats Elefant on is memory used rendering a template. I think this is because Elefant's template naming uses an "appname/viewname" format, which has to be parsed and matched against the filesystem. This adds overhead for the convenience of not having to specify full file paths, but still comes out faster since the compiled PHP is simpler. Here's the compiled output for the three template engines for comparison:

  • Interesting. I do love elefants templating engine. Particularly because I can go look at the output and quickly understand what is going on if something isn't working.

  • That's something I should make better note of in the documentation. It's saved me a good deal of trouble more than once!

  • I would love to know how to be able to do that as well! Definitely seems helpful.

  • Just look in the cache folder. If a template is named layouts/foo.html, it'll be cached to cache/foo.php. If it's a template in an app, e.g. apps/user/views/sidebar.html it'll be cached to cache/user-sidebar.php

  • Okay...will check that out.

  • Wow pretty impressive results :)

  • Impressive and very interesting

Sign In or Register to comment.