-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbenchmarks.php
44 lines (34 loc) · 973 Bytes
/
benchmarks.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
$tmpl = <<<EOF
<div class="entry">
<h1>{{title}}</h1>
<div class="body">
{{body}}
</div>
</div>
EOF;
$data = array(
'title' => 'My New Post',
'body' => 'This is my first post!',
);
$vm = new Handlebars\VM();
$iterations = 100000;
// standard
$vm->render($tmpl, $data);
$start = microtime(true);
for ($i = 0; $i < $iterations; $i++ ) {
$vm->render($tmpl, $data);
}
$end = microtime(true);
$delta = $end - $start;
printf("%-12s iterations=%d cacheBackend=%-6s time=%g\n", "standard", $iterations, Handlebars\CACHE_BACKEND, $delta);
// precompiled
$binaryString = $vm->compile($tmpl);
$vm->renderFromBinaryString($binaryString, $data);
$start = microtime(true);
for ($i = 0; $i < $iterations; $i++ ) {
$vm->renderFromBinaryString($binaryString, $data);
}
$end = microtime(true);
$delta = $end - $start;
printf("%-12s iterations=%d cacheBackend=%-6s time=%g\n", "precompiled", $iterations, Handlebars\CACHE_BACKEND, $delta);