Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Test question from reddit whether than closing PHP tag and echoing is faster
- * than echo function.
- */
- /**
- * The total number of times each test will run.
- *
- * @var int
- */
- $iterations = 50000;
- /**
- * Stores the total number of microseconds of runtime.
- */
- $runtime = 0;
- //////////// FIRST TEST //////////////////
- $a = 'a';
- $b = 'a';
- ob_start();
- for( $i = 0; $i < $iterations; $i++) {
- $start = microtime();
- if($a == $b) : ?><li>My gran can beat you at <?php echo $b; ?> no problem.</li><?php endif;
- $end = microtime();
- $runtime += ($end - $start);
- }
- ob_end_clean();
- $avgRuntime = $runtime / $iterations;
- printf( "Test 1 ran %s times. Average runtime was %s microseconds\n", $iterations, $avgRuntime );
- $runtime = 0;
- $a = 'a';
- $b = 'a';
- ob_start();
- for( $i = 0; $i < $iterations; $i++) {
- $start = microtime();
- if($a == $b) echo '<li>My gran can beat you at '. $b .' No problem.</li>';
- $end = microtime();
- $runtime += ($end - $start);
- }
- ob_end_clean();
- $avgRuntime = $runtime / $iterations;
- printf( "Test 2 ran %s times. Average runtime was %s microseconds\n", $iterations, $avgRuntime );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement