Smarty benchmark, anyone?

前端 未结 10 1932
旧时难觅i
旧时难觅i 2021-01-05 05:05

I am considering Smarty as my web app templating solution, and I am now concerned with its performance against plain PHP.

The Smarty site says it should be the same

相关标签:
10条回答
  • 2021-01-05 05:30

    Based on my own experiences and informal benchmarks, Smarty doesn't by itself cause any major performance reductions. However, when you get into writing custom plugins, things go downhill.

    A Smarty template is compiled & cached as PHP, but a custom plugin is always loaded and executed at runtime and is always slower than running the same code in a plain old PHP file. You're not going to notice this too much with a custom string formatting plugin, but you'll definitely see it when doing database queries in a plugin.

    Overall, I highly recommend Smarty. Getting the display out of the PHP has made our code so much more readable and maintainable. You just have to make sure you're careful about what you put in plugins.

    0 讨论(0)
  • 2021-01-05 05:34

    There is a drop in replacement for Smarty called Template Lite which is much more lightweight in respect to the library file size. That said, I have used the original Smarty in some extremely high load situations without needing to swap in this library.

    0 讨论(0)
  • 2021-01-05 05:38

    It depends on how you use Smarty because the flow of your pages can change

    Classic plain PHP flow:

    • Output
    • Handle $_REQUEST data
    • Output
    • Handle database queries
    • Output
    • Handle $_REQUEST data
    • Output
    • ...

    Classic Smarty flow:

    • Handle all $_REQUEST data
    • Handle all database queries
    • Output all

    If plain PHP took 1.0 sec for this page the Smarty page also takes 1.0 sec. BUT if we assume that all database and $_request handeling takes 0.7 sec. The plain PHP starts output directly while the Smarty version starts outputing after 0.7 sec. Therefor the browser can start downloading stylesheets and images faster. No output also means the "Stop" button has no effect.

    However in Smarty you can call functions and methods from within the template. Delaying the slow part to where the data is needed.

    0 讨论(0)
  • 2021-01-05 05:43

    Here a template engine benchmark that tests PHP vs Smarty and many more template engines http://www.raintpl.com/PHP-Template-Engines-Speed-Test/

    • For assignment Twig is the faster, it compile the html template to a classes, so it's also faster in executing more than the PHP include! IMHO is heavy (many files) and complicate, but is very fast!

    • For looping the faster is the PHP include, and soon after there's Rain which is very easy, small (1 file) and fast.

    0 讨论(0)
提交回复
热议问题