Skip to content

Instantly share code, notes, and snippets.

@splittingred
Created March 9, 2012 05:37
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save splittingred/2005200 to your computer and use it in GitHub Desktop.
Save splittingred/2005200 to your computer and use it in GitHub Desktop.
simple-benchmark.php
<?php
set_time_limit(0);
class Timer {
public $timer = 0;
public function start() {
$mtime = microtime();
$mtime = explode(" ", $mtime);
$mtime = $mtime[1] + $mtime[0];
$this->timer = $mtime;
}
public function end() {
$mtime= microtime();
$mtime= explode(" ", $mtime);
$mtime= $mtime[1] + $mtime[0];
$tend= $mtime;
$totalTime= ($tend - $this->timer);
$totalTime= sprintf("%2.4f s", $totalTime);
return $totalTime;
}
}
$timer = new Timer();
define('NUMBER_OF_TIMES',1000);
$totalDrupal = 0;
$totalModx = 0;
for ($i=0;$i<NUMBER_OF_TIMES;$i++) {
$timer->start();
$drupal = file_get_contents('http://localhost/drupal712/');
$drupalt = $timer->end();
$totalDrupal += $drupalt;
$timer->start();
$modx = file_get_contents('http://localhost/modx-2.2.0-pl2/');
$modxt = $timer->end();
$totalModx += $modxt;
}
$averageDrupal = $totalDrupal / NUMBER_OF_TIMES;
$averageModx = $totalModx / NUMBER_OF_TIMES;
echo 'Number of times: '.NUMBER_OF_TIMES."\n<br />";
echo 'Average Drupal: '.$averageDrupal."\n<br />";
echo 'Average MODX: '.$averageModx."\n<br />";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment