Skip to content

Instantly share code, notes, and snippets.

@nikic
Last active October 28, 2021 07:57
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nikic/289b0c7538b46c2220bc to your computer and use it in GitHub Desktop.
Save nikic/289b0c7538b46c2220bc to your computer and use it in GitHub Desktop.
Scripts for measuring compile time
<?php ini_set('memory_limit', -1);
if ($argc != 3) die("error\n");
$file = $argv[1];
$num = $argv[2];
$startTime = microtime(true);
for ($i = 0; $i < $num; ++$i) {
require $file;
}
echo "Compile time: ", microtime(true) - $startTime, " seconds\n";
echo "Peak memory usage: ", memory_get_peak_usage(), " bytes\n";
<?php error_reporting(E_ALL);
$dir = __DIR__ . '/../PHP-Parser/lib';
spl_autoload_register(function($class) use($dir) {
if (strpos($class, 'PhpParser') === 0) {
require $dir . '/' . strtr($class, '\\', '/') . '.php';
}
});
$it = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($dir . '/PhpParser'), RecursiveIteratorIterator::LEAVES_ONLY);
$startTime = microtime(true);
foreach ($it as $file) {
if (!$file->isFile()) continue;
require_once $file;
}
echo "Compile time: ", microtime(true) - $startTime, " seconds\n";
echo "Peak memory usage: ", memory_get_peak_usage(), " bytes\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment