_start = array_sum(explode(' ', microtime())); } function tick() { $this->_current = round((array_sum(explode(' ', microtime()))-$this->_start)*1000, 0); return $this->_current; } function reset() { $this->timer(); } } echo "\r\n"; ob_start(); ob_implicit_flush(0); //////////////////////////////////////////////////////////////////////////////// /*////////////////////////////////////////////////////////////////////////////// for($i=0;$i<$iterations;$i++) { echo 'Okay. I am going '.$data.' to concatenate the $data string '.$data.' a few times between this sentence. '.$data; } ob_clean(); //////////////////////////////////////////////////////////////////////////////*/ //////////////////////////////////////////////////////////////////////////////// $t5c = new timer(); for($i=0;$i<$iterations;$i++) { echo 'Okay. I am going '.$data.' to concatenate the $data string '.$data.' a few times between this sentence. '.$data; } $t5c = $t5c->tick(); if($t5c > $max) $max = $t5c; ob_clean(); //////////////////////////////////////////////////////////////////////////////// $t5 = new timer(); for($i=0;$i<$iterations;$i++) { echo 'Okay. I am going This is data to be concatenated. It is long, so as to make it take longer to concatenate and hence widen the gap between the faster and the slower of the methods. to concatenate the $data string This is data to be concatenated. It is long, so as to make it take longer to concatenate and hence widen the gap between the faster and the slower of the methods. a few times between this sentence. This is data to be concatenated. It is long, so as to make it take longer to concatenate and hence widen the gap between the faster and the slower of the methods.'; } $t5 = $t5->tick(); if($t5 > $max) $max = $t5; ob_clean(); //////////////////////////////////////////////////////////////////////////////// $t6c = new timer(); for($i=0;$i<$iterations;$i++) { echo "Okay. I am going $data to concatenate the \$data string $data a few times between this sentence. $data"; } $t6c = $t6c->tick(); if($t6c > $max) $max = $t6c; ob_clean(); //////////////////////////////////////////////////////////////////////////////// $t6 = new timer(); for($i=0;$i<$iterations;$i++) { echo "Okay. I am going This is data to be concatenated. It is long, so as to make it take longer to concatenate and hence widen the gap between the faster and the slower of the methods. to concatenate the \$data string This is data to be concatenated. It is long, so as to make it take longer to concatenate and hence widen the gap between the faster and the slower of the methods. a few times between this sentence. This is data to be concatenated. It is long, so as to make it take longer to concatenate and hence widen the gap between the faster and the slower of the methods."; } $t6 = $t6->tick(); if($t6 > $max) $max = $t6; ob_clean(); //////////////////////////////////////////////////////////////////////////////// $t7c = new timer(); for($i=0;$i<$iterations;$i++) { echo <<tick(); if($t7c > $max) $max = $t7c; ob_clean(); //////////////////////////////////////////////////////////////////////////////// $t7 = new timer(); for($i=0;$i<$iterations;$i++) { echo <<tick(); if($t7 > $max) $max = $t7; ob_clean(); //////////////////////////////////////////////////////////////////////////////// $t8c = new timer(); for($i=0;$i<$iterations;$i++) { printf('Okay. I am going %s to concatenate the $data string %s a few times between this sentence. %s', $data, $data, $data); } $t8c = $t8c->tick(); if($t8c > $max) $max = $t8c; ob_clean(); //////////////////////////////////////////////////////////////////////////////// $t8 = new timer(); for($i=0;$i<$iterations;$i++) { printf('Okay. I am going This is data to be concatenated. It is long, so as to make it take longer to concatenate and hence widen the gap between the faster and the slower of the methods. to concatenate the $data string This is data to be concatenated. It is long, so as to make it take longer to concatenate and hence widen the gap between the faster and the slower of the methods. a few times between this sentence. This is data to be concatenated. It is long, so as to make it take longer to concatenate and hence widen the gap between the faster and the slower of the methods.'); } $t8 = $t8->tick(); if($t8 > $max) $max = $t8; ob_clean(); //////////////////////////////////////////////////////////////////////////////// ob_end_clean(); echo "

Benchmark: send to page

\r\n"; echo "

No concatenation

\r\n"; echo "\r\nsingle quotes ($t1 ms)
\r\n". "
"; echo "\r\ndouble quotes ($t2 ms)
\r\n". "
"; echo "\r\nheredoc ($t3 ms)
\r\n". "
"; echo "\r\nprintf ($t4 ms)
\r\n". "
"; echo "

With concatenation

\r\n"; echo "\r\nsingle quotes ($t1c ms)
\r\n". "
"; echo "\r\ndouble quotes ($t2c ms)
\r\n". "
"; echo "\r\nheredoc ($t3c ms)
\r\n". "
"; echo "\r\nprintf ($t4c ms)
\r\n". "
"; echo "
\r\n

Benchmark: send to output buffer

"; echo "

No concatenation

\r\n"; echo "\r\nsingle quotes ($t5 ms)
\r\n". "
"; echo "\r\ndouble quotes ($t6 ms)
\r\n". "
"; echo "\r\nheredoc ($t7 ms)
\r\n". "
"; echo "\r\nprintf ($t8 ms)
\r\n". "
"; echo "

With concatenation

\r\n"; echo "\r\nsingle quotes ($t5c ms)
\r\n". "
"; echo "\r\ndouble quotes ($t6c ms)
\r\n". "
"; echo "\r\nheredoc ($t7c ms)
\r\n". "
"; echo "\r\nprintf ($t8c ms)
\r\n". "
"; ?>