Location: PHPKode > scripts > CBenchmark > cbenchmark/example1.php
<?php
/**
 * Example of using CBenchmark class to compare execution of 
 * particular functions
 *
 */
define('TESTCOUNT',1000);
define('TESTSUBJECT','Quick brown fox jumps over the lazy dog.');
require_once('clsBenchMark.php');
$bench=new CBenchmark();

/**
 * Provide which functions to be benchmarked
 */
$bench->do_benchmark('Test PREG_REPLACE','test_preg_replace');
$bench->do_benchmark('Test STR_REPLACE','test_str_replace');

$bench->ShowResults();


function test_preg_replace(){
	for($i=0;$i<TESTCOUNT;$i++){
		preg_replace('/fox/','hare',TESTSUBJECT);
	}
}

function test_str_replace(){
	for($i=0;$i<TESTCOUNT;$i++){
		str_replace('fox','hare',TESTSUBJECT);
	}
}
?>
Return current item: CBenchmark