-
Notifications
You must be signed in to change notification settings - Fork 0
/
benchmark.php
executable file
·89 lines (76 loc) · 2.25 KB
/
benchmark.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env php
<?php
use Symfony\Component\Finder\Finder;
require __DIR__ . '/vendor/autoload.php';
echo "PHP: " . \phpversion() . "\n";
echo "Xdebug: " . (extension_loaded("xdebug") ? "on" : "off") . "\n";
echo "OPCache: " . (extension_loaded("Zend OPcache") ? "on" : "off") . "\n";
$fileNames = (new Finder())->in(__DIR__ . '/src/Nodes/')->filter(function (\SplFileInfo $p)
{
return $p->getExtension() === 'php';
});
$fileNames = array_map('strval', iterator_to_array($fileNames));
$reps = 10;
$files = [];
foreach ($fileNames as $fileName)
{
$files[$fileName] = file_get_contents($fileName);
}
echo count($fileNames) . ' file(s), ' . $reps . " rep(s)\n";
gc_collect_cycles();
//*
echo "phi (without validation)... ";
$lexer = new \Phi\Lexer(PHP_VERSION_ID);
$parser = new \Phi\Parser(PHP_VERSION_ID);
$maxMemory = 0;
$start = microtime(true);
for ($i = 0; $i < $reps; $i++)
{
foreach ($files as $fileName => $contents)
{
$ast = $parser->parse($fileName, $contents);
$maxMemory = max($maxMemory, memory_get_usage());
unset($ast);
}
}
$time = microtime(true) - $start;
echo number_format($time, 3) . "s, " . number_format($maxMemory / 1e6, 2) . "MB\n";
//*/
gc_collect_cycles();
//*
echo "phi (with validation)... ";
$lexer = new \Phi\Lexer(PHP_VERSION_ID);
$parser = new \Phi\Parser(PHP_VERSION_ID);
$maxMemory = 0;
$start = microtime(true);
for ($i = 0; $i < $reps; $i++)
{
foreach ($files as $fileName => $contents)
{
$ast = $parser->parse($fileName, $contents);
$ast->validate();
$maxMemory = max($maxMemory, memory_get_usage());
unset($ast);
}
}
$time = microtime(true) - $start;
echo number_format($time, 3) . "s, " . number_format($maxMemory / 1e6, 2) . "MB\n";
//*/
gc_collect_cycles();
//*
echo "nikic/php-parser... ";
$parser = (new \PhpParser\ParserFactory())->create(\PhpParser\ParserFactory::PREFER_PHP7);
$maxMemory = 0;
$start = microtime(true);
for ($i = 0; $i < $reps; $i++)
{
foreach ($files as $fileName => $contents)
{
$ast = $parser->parse($contents);
$maxMemory = max($maxMemory, memory_get_usage());
unset($ast);
}
}
$time = microtime(true) - $start;
echo number_format($time, 3) . "s, " . number_format($maxMemory / 1e6, 2) . "MB\n";
//*/