rendered paste body<?php
define( 'MAX', 10000 );
define( 'EVERY', 1000 );
$string = 'some crap here, replace this, more crap here';
$start = getMicrotime();
echo '<h3>str_replace</h3>';
for( $i = 0; $i < MAX; $i++ )
{
str_replace( 'replace this', '', $string );
$time = getMicrotime() - $start;
if( $i % EVERY == 0 )
echo $time.'<br/>';
}
$start = getMicrotime();
echo '<h3>preg_replace</h3>';
for( $i = 0; $i < MAX; $i++ )
{
preg_replace( '#replace this#', '', $string );
$time = getMicrotime() - $start;
if( $i % EVERY == 0 )
echo $time.'<br/>';
}
$start = getMicrotime();
echo '<h3>preg_replace (case insensitive)</h3>';
for( $i = 0; $i < MAX; $i++ )
{
preg_replace( '#Replace this#i', '', $string );
$time = getMicrotime() - $start;
if( $i % EVERY == 0 )
echo $time.'<br/>';
}
function getMicrotime()
{
list( $usec, $sec ) = explode (' ', microtime() );
return ( (float) $sec + (float) $usec );
}
?>