https://github.com/terales/twig-if-perfomance
[RESEARCH] How `if` operator performs with inline vs included large templates
https://github.com/terales/twig-if-perfomance
Last synced: about 2 months ago
JSON representation
[RESEARCH] How `if` operator performs with inline vs included large templates
- Host: GitHub
- URL: https://github.com/terales/twig-if-perfomance
- Owner: terales
- License: mit
- Created: 2017-09-29T18:48:55.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-10-30T15:46:20.000Z (over 7 years ago)
- Last Synced: 2025-01-17T16:37:25.252Z (4 months ago)
- Language: HTML
- Size: 5.86 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Performance difference between inline and included operators inside `if` branches
[Response]((https://github.com/twigphp/Twig/issues/2576#issuecomment-340398831)) from [@stof](https://github.com/stof), one of the Twig contributors:
> your test is unfair: you don't compare rendering time. You compare the compile+rendering time. And your test for `include-version.twig` does not recompile the `inline-version.twig` template as it is already compiled by the previous rendering. Change the order of both cases, and you will see the opposite number.
The only thing that your benchmark is showing is that compiling templates takes more time than reusing the already compiled one (which is something we know since ages, which is why Twig is able to store the compiled template in a persistent cache).Checked it and that's true, no such issue there.
## Experiment data
1. Install dependencies in `./twig1` and `./twig2` folders
1. Run `php index.php` to test with Twig 1.0.
1. Change `require_once './twig1/…';` to `require_once './twig2/…';` and run `php index.php` to test with Twig 2.0.My results in seconds:
```
// PHP 5.6 + Twig2
inline-version.twig: 0.2901
include-version.twig: 0.0051// PHP 7.1 + Twig1
inline-version.twig: 0.0432
include-version.twig: 0.0012// PHP 7.1 + Twig2
inline-version.twig: 0.0391
include-version.twig: 0.0011
```