* @copyright 2024 smiley * @license MIT * * @phan-file-suppress PhanTypeArraySuspiciousNullable */ declare(strict_types=1); namespace chillerlan\QRCodeBenchmark; use RuntimeException; use function array_keys; use function copy; use function file_exists; use function file_get_contents; use function file_put_contents; use function htmlspecialchars; use function implode; use function is_bool; use function is_dir; use function json_decode; use function mkdir; use function sprintf; require_once __DIR__.'/parse-common.php'; if(!file_exists(FILE.'.json')){ throw new RuntimeException('invalid benchmark report'); } $json = json_decode(file_get_contents(FILE.'.json'), true); $htmlHead = ' %s results '; $htmlFoot = ' '; $html = []; // General information/overview $env = $json['env']; $suite = $json['suite']; $html['index'][] = sprintf($htmlHead, 'Benchmark'); $html['index'][] = '

Benchmark results

'; $html['index'][] = '

Environment

'; $html['index'][] = ''; $html['index'][] = ''; $html['index'][] = ''; $html['index'][] = sprintf('', $suite['date'], $suite['time']); $html['index'][] = sprintf('', $env['uname_os'], $env['uname_version'], $env['uname_machine']); $html['index'][] = sprintf('', htmlspecialchars($suite['tag'])); foreach(['php_version', 'php_ini', 'php_extensions', 'php_xdebug', 'opcache_extension_loaded', 'opcache_enabled'] as $field){ // prettify the boolean values if(is_bool($env[$field])){ $env[$field] = ($env[$field]) ? '✓' : '✗'; } $html['index'][] = sprintf('', $field, $env[$field]); } $html['index'][] = '
NameValue
date%s %s
environment%s %s, %s
tag%s
%s%s
'; // list indiviidual reports $html['index'][] = '

Reports

'; $list = []; foreach(array_keys($json['benchmark']) as $benchmark){ // add a file & header $html[$benchmark][] = sprintf($htmlHead, $benchmark); $html[$benchmark][] = sprintf('

%s

', $benchmark); $html[$benchmark][] = sprintf('%s', $json['benchmark'][$benchmark]['class']); foreach(array_keys($json['benchmark'][$benchmark]['subjects']) as $subject){ // list item $list[$benchmark][] = $subject; $subj = $json['benchmark'][$benchmark]['subjects'][$subject]; $html[$benchmark][] = sprintf('

%1$s

', $subject); $html[$benchmark][] = sprintf('
Revs: %s, Iterations: %s
', $subj['revs'], $subj['iterations']); $html[$benchmark][] = parseVariants($subj['variants']); } // close document $html[$benchmark][] = 'back to overview'; $html[$benchmark][] = $htmlFoot; } // create overview list $html['index'][] = ''; // close document $html['index'][] = $htmlFoot; if(!is_dir(BUILDDIR.'/html/')){ mkdir(BUILDDIR.'/html/'); } copy('./benchmark.css', BUILDDIR.'/html/benchmark.css'); foreach($html as $file => $content){ file_put_contents(BUILDDIR.'/html/'.$file.'.html', implode("\n", $content)); }