-
Notifications
You must be signed in to change notification settings - Fork 146
/
Copy path1.php
44 lines (33 loc) · 1.22 KB
/
1.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
/* The Computer Language Benchmarks Game
https://salsa.debian.org/benchmarksgame-team/benchmarksgame/
contributed by Peter Baltruschat
modified by Levi Cameron
modified by Stéphane Demonchaux
*reset*
must run with
opcache.jit=1255
opcache.enable_cli=1
opcache.jit_buffer_size=100M
memory_limit=400M
*/
function checksum(array|null $node):int {
return $node[0] === null ? 1 : 1 + checksum($node[0]) + checksum($node[1]);
}
function createTree(int $depth): array|null {
return $depth-- > 0 ? [createTree($depth), createTree($depth)] : [null, null];
}
$maxDepth = max(6, ($argc == 2) ? $argv[1] : 1);
$stretchDepth = $maxDepth + 1;
$stretchTree = createTree($stretchDepth);
echo sprintf("stretch tree of depth %s\t check: %s\n", $stretchDepth, checksum($stretchTree));
$longLivedTree = createTree($maxDepth);
for ($depth = 4; $depth <= $maxDepth; $depth += 2) {
$iterations = 1 << $maxDepth - $depth + 4;
$sum = 0;
for ($i = 0; $i < $iterations; $i++) {
$sum += checksum(createTree($depth));
}
echo sprintf("%s\t trees of depth %s\t check: %s\n", $i, $depth, $sum);
}
echo sprintf("long lived tree of depth %s\t check: %s\n", $maxDepth, checksum($longLivedTree));