Created
December 7, 2012 17:41
-
-
Save Mark-H/4234992 to your computer and use it in GitHub Desktop.
MODX Performance Benchmark Snippet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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
Note that you need to create a "benchmark" chunk with [[+idx]] in it as well when trying this. Use at own risk.