- substr_count: documentation ( source)
- microtime: documentation ( source)
- str_shuffle: documentation ( source)
- preg_match_all: documentation ( source)
<?php
$str = '';
for( $i = 0; $i <= 100; $i++ ) {
$str .= str_shuffle('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ');
}
$start = microtime(true);
for( $i = 0; $i<800000; $i++ ) {
substr_count( 'foobar', $str );
}
echo "count: " . (microtime(true)-$start) . PHP_EOL;
$start = microtime(true);
for( $i = 0; $i<800000; $i++ ) {
preg_match_all( '/foobar/', $str );
}
echo "rcount: " . (microtime(true)-$start) . PHP_EOL;