Online education portals like Udacity and Coursera are really changing the world of remote learning in significant ways. By making free and high quality education accessible to a global audience, these platforms are opening up undreamt of possibilities for communities around the world to improve, grow, and prosper in the digital economy of the 21st century. Education at top tier colleges and universities has traditionally been a social and economic privilege, but now anyone can join in the learning revolution by sitting in virtual classrooms with the world’s best and brightest educators. Whether this involves learning how to code and build smart phone apps, or starting up a new business, or learning about public health literacy, the sky is the limit of what’s now possible.

Everything about Web and Network Monitoring

Test Harness for PHP Performance

A few days ago, I gave you my JavaScript test harness. I created it so I could evaluate some of the performance options that were listed in Website Performance: JavaScript. As promised, here is the same test harness ported over to PHP. [I hope you don’t laugh at me when I tell you I spent over an hour debugging a missing dollar sign.]


  //Test Harness for PHP performance.  It handles up to three alternatives.
  //Just copy/paste your code to the lines that say "INSERT CODE TO BE
  //TESTED HERE," then upload to the server and surf to this web page.
  //Written by Warren Gaebel, B.A., B.C.S.
  //Released into public domain 2012.04.03.

  $numReps = 100;      //adjust this value; 1,000,000 may work well
  $numberOfTests = 1;  //adjust this value; 100 may work well
  $o1timeSum = 0;
  $o2timeSum = 0;
  $o3timeSum = 0;
  $timeDiff12 = 0;
  $timeDiff13 = 0;
  $timeDiff23 = 0;
  $timeDiff12Sum = 0;
  $timeDiff13Sum = 0;
  $timeDiff23Sum = 0;

  for ($j = $numberOfTests; $j--;) {
    echo ("<br />Test # " . ($numberOfTests - $j) . ":");

    // OPTION #1
    $o1start = time();
    for ($i = $numReps; $i--;) {
    $o1stop = time();
    $o1time = $o1stop - $o1start;
    $o1timeSum += $o1time;
    echo ("   Option #1:  " . $o1time);

    // OPTION #2
    $o2start = time();
    for ($i = $numReps; $i--;) {
    $o2stop = time();
    $o2time = $o2stop - $o2start;
    $o2timeSum += $o2time;
    echo ("   Option #2:  " . $o2time);

    // OPTION #3
    $o3start = time();
    for ($i = $numReps; $i--;) {
    $o3stop = time();
    $o3time = $o3stop - $o3start;
    $o3timeSum += $o3time;
    echo ("   Option #3:  " . $o3time);

    $timeDiff12Sum += ($timeDiff12 = $o1time - $o2time);
    $timeDiff13Sum += ($timeDiff13 = $o1time - $o3time);
    $timeDiff23Sum += ($timeDiff23 = $o2time - $o3time);

  echo ("<br />");
  echo ("<br />Average Time for Option 1: " . ($o1timeSum / $numberOfTests));
  echo ("<br />Average Time for Option 2: " . ($o2timeSum / $numberOfTests));
  echo ("<br />Average Time for Option 3: " . ($o3timeSum / $numberOfTests));
  echo ("<br />");
  echo ("<br />Time Difference (1-2): " . ($timeDiff12Sum / $numberOfTests));
  echo ("<br />Time Difference (1-3): " . ($timeDiff13Sum / $numberOfTests));
  echo ("<br />Time Difference (2-3): " . ($timeDiff23Sum / $numberOfTests));


It’s the same algorithm as in the JavaScript version, so the usage instructions and interpretation are the same. Please keep in mind the warnings in that last article, though. The PHP version is better because you can test your options on the production machine that will eventually run it, but it still suffers from the random effects of whatever happens to be running in the background. You may get significantly different results at peak time vs. quiet time, so don’t rely on only one or two tests.

These two test harnesses are quick and simple, but I’m already thinking of improvements to them. You can probably see some opportunities, too. It’s a good thing it’s in the public domain – you can customize it to your heart’s content.

I hope this helps.

Post Tagged with

About Warren Gaebel

Warren wrote his first computer program in 1970 (yes, it was Fortran).  He earned his Bachelor of Arts degree from the University of Waterloo and his Bachelor of Computer Science degree at the University of Windsor.  After a few years at IBM, he worked on a Master of Mathematics (Computer Science) degree at the University of Waterloo.  He decided to stay home to take care of his newborn son rather than complete that degree.  That decision cost him his career, but he would gladly make the same decision again. Warren is now retired, but he finds it hard to do nothing, so he writes web performance articles for the Monitor.Us blog.  Life is good!