|
12 | 12 |
|
13 | 13 | require __DIR__ . '/../vendor/autoload.php'; |
14 | 14 |
|
15 | | -$iterations = (int) ($argv[1] ?? 1000); |
| 15 | +$iterations = (int) ($argv[1] ?? 1); |
16 | 16 |
|
17 | 17 | // A large, complex template exercising as many syntax features as possible. |
18 | 18 | $template = loadTemplate('large-page'); |
|
84 | 84 | knownHelpersOnly: $knownHelpersOnly, |
85 | 85 | ); |
86 | 86 |
|
87 | | -// Warm up: give the JIT a chance to compile hot paths before we measure. |
88 | | -for ($i = 0; $i < 50; $i++) { |
89 | | - Handlebars::precompile($template, $options); |
90 | | - foreach ($partialTemplates as $src) { |
91 | | - Handlebars::precompile($src, $options); |
92 | | - } |
93 | | -} |
94 | | - |
95 | 87 | memory_reset_peak_usage(); |
96 | 88 | $start = hrtime(true); |
97 | 89 |
|
98 | | -for ($i = 0; $i < $iterations; $i++) { |
99 | | - Handlebars::precompile($template, $options); |
100 | | - foreach ($partialTemplates as $src) { |
101 | | - Handlebars::precompile($src, $options); |
102 | | - } |
103 | | -} |
104 | | - |
105 | | -$elapsed = (hrtime(true) - $start) / 1e9; |
106 | | -$compilePeakMB = memory_get_peak_usage() / 1024 / 1024; |
107 | | -$perParse = $elapsed / $iterations * 1000; |
108 | 90 | $php = Handlebars::precompile($template, $options); |
109 | 91 | $codeBytes = strlen($php); |
110 | 92 | $partials = []; |
|
115 | 97 | $partials[$name] = Handlebars::template($code); |
116 | 98 | } |
117 | 99 |
|
| 100 | +$elapsed = (hrtime(true) - $start) / 1e9; |
| 101 | +$compilePeakMB = memory_get_peak_usage() / 1024 / 1024; |
| 102 | +$perParse = $elapsed / $iterations * 1000; |
| 103 | + |
118 | 104 | printf( |
119 | 105 | "Compiled %d times | %.2f ms/compile | %6.1f KB code | %.1f MB peak\n", |
120 | 106 | $iterations, |
|
248 | 234 |
|
249 | 235 | // Warm up |
250 | 236 | for ($i = 0; $i < 50; $i++) { |
| 237 | + echo "Render $i..."; |
251 | 238 | $renderer($data, ['helpers' => $helpers, 'partials' => $partials]); |
| 239 | + echo "complete\n"; |
252 | 240 | } |
253 | 241 |
|
254 | 242 | memory_reset_peak_usage(); |
|
0 commit comments