Page MenuHomePhabricator
Paste P897

rl_hash.php
ActivePublic

Authored by Krinkle on Jul 7 2015, 7:10 AM.
Referenced Files
F189711: rl_hash.php
Jul 7 2015, 7:16 AM
F189706: rl_hash.php
Jul 7 2015, 7:10 AM
Subscribers
None
<?php
// Benchmark as part of T102578
require __DIR__ . '/includes/WebStart.php';
#require '/srv/mediawiki/w/MWVersion.php';
#require getMediaWiki('includes/WebStart.php');
function kfSafeFilemtime($filePath) {
MediaWiki\suppressWarnings();
$v = filemtime($filePath) ?: 1;
MediaWiki\restoreWarnings();
return $v;
}
function kfSafeFileSha1($filePath) {
MediaWiki\suppressWarnings();
$v = sha1_file($filePath) ?: '';
MediaWiki\restoreWarnings();
return $v;
}
function kfSafeFileMd5($filePath) {
MediaWiki\suppressWarnings();
$v = md5_file($filePath) ?: '';
MediaWiki\restoreWarnings();
return $v;
}
$dir = new RecursiveDirectoryIterator($IP . '/resources', FilesystemIterator::SKIP_DOTS);
$iterator = new RecursiveIteratorIterator($dir);
$fileCount = iterator_count($iterator);
set_time_limit(0);
$data = array();
foreach (array(
'filemtime' => 'kfSafeFilemtime',
'sha1_file' => 'kfSafeFileSha1',
'md5_file' => 'kfSafeFileMd5',
) as $method => $fn) {
for ($i = 0; $i < 32; $i++) {
$start = microtime(true);
foreach ($iterator as $key => $value) {
$fn( $value);
}
$timing = microtime(true) - $start;
if ($i < 2) {
$data[$method]['warmups'][] = $timing;
} else {
$data[$method]['main'][] = $timing;
}
}
}
$phpVersion = (wfIsHHVM() ? 'HHVM ' . HHVM_VERSION : 'PHP ' . PHP_VERSION )
. ' (' . PHP_SAPI . ')';
header( 'Content-Type: text/html; charset=utf-8' );
echo '<h1>Benchmark</h1>'
. '<p><em>Part of <a href="https://phabricator.wikimedia.org/T102578">T102578</a>.</em></p>'
. '<table>'
. '<tr><th>PHP</th><td>' . htmlspecialchars($phpVersion) . '</td></tr>'
. '<tr><th>OS</th><td>' . htmlspecialchars(PHP_OS) . '</td></tr>'
. '<tr><th>Input</th><td>resources/**/* (' . intval($fileCount) . ' files)</td></tr>'
. '</table>';
foreach ( $data as $method => $data ) {
echo "<h2>$method</h2><table>";
foreach ($data as $group => $timings) {
echo "<tr><th>$group</th><td>"
. ((array_sum($timings) / count($timings)) * 1000 )
. 'ms total on average (' . count($timings) . ' samples)'
. '</td></tr>';
}
echo '</table>';
}

Event Timeline

Krinkle changed the title of this paste from untitled to rl_hash.php.
Krinkle updated the paste's language from autodetect to autodetect.
Krinkle updated the paste's language from autodetect to php.