Skip to content

Instantly share code, notes, and snippets.

@exside
Forked from Mark-H/benchmark.php
Created March 2, 2013 23:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save exside/5073740 to your computer and use it in GitHub Desktop.
Save exside/5073740 to your computer and use it in GitHub Desktop.
<?php
// Use this line to prevent people from hammering your server.
if (!isset($_GET['super_secret']) || ($_GET['super_secret'] != 'secretpassword')) return 'Not authorized';
// Call this snippet uncached in a resource with template "empty":
// content: "[[!benchmark]]"
// Make sure to tag the resource as uncachable
// The intro
echo '<body style="font-family: sans-serif;">';
echo '<h1>MODX benchmark</h1>';
echo "<h2>Fetching the current resource from the API and parsing it through a chunk a lot</h1>";
$timingQueries = 0;
$timingParsing = 0;
// The loop running the test string 100x (a hundred times)
$o = 'Lap: ';
for ($i=1; $i <= 500; $i++) {
$start = microtime(true);
$res = $modx->getObject('modResource', $modx->resource->id);
$data = array('id' => $res->get('id'), 'idx' => $i);
//$data = array('id' => $i, 'idx' => $i);
$timingQueries += (microtime(true) - $start);
$start = microtime(true);
$o .= $i . $modx->getChunk('benchmark',$data) . " \n";
$timingParsing += (microtime(true) - $start);
}
$o .= 'done.';
$o .= '<table>
<tr><td width="100">Queries</td><td width="250">'.$timingQueries.'</td></tr>
<tr><td>Parsing</td><td width="250">'.$timingParsing.'</td></tr>
<tr><td>Total</td><td>[^p^]</td></tr>
<tr><td>Source</td><td>[^s^]</td></tr>';
$o .= '<hr />
<h2>Do not forget to STOP THE BROWSER manually, because this script will run like FOREVER!!!</h2>
<h2>Hit the X-button near the URL field or just close this website after some cycles.</h2>
</body></html>';
return $o;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment