On January 29, 2003 04:35 pm, Shane Caraveo wrote: > What's the benchmark code? How is the benchmark difference on large > text (ie. 100K of text) vs. small text (1K or smaller)?
Attached is the benchmark script that I've used. I've intentionally used 'small' strings, since that is what I imagine is most common usage of the function. Ilia
<?php $input[] = array('hfdhffndfafjdfjasfjas;fjdas;fjdsafjas;fjas', 'das', '1234'); $input[] = array('Used the form above or our advanced search page to make sure nobody has reported the bug already.', 'or', 'OR'); $input[] = array('Once you\'ve double-checked that the bug you\'ve found hasn\'t already been reported, and that you have collected all the information you need to file an excellent bug report, you can do so on our bug reporting page.', 'XYS', '1234'); $input[] = array('dfkfjgjdsgjdgfd', 'dfkfjgjdsgjdgfd', '13243'); $input[] = array('xif pleh ot tnaw lliw enoemos taht gub a troper ot woh no spit ruo daeR', 'Read our tips on how to report a bug that someone will want to help fix', '13243'); function getmicrotime() { list($usec, $sec) = explode(" ",microtime()); return ((float)$usec + (float)$sec); } $start = getmicrotime(); for ($i = 0; $i < 100000; $i++) { foreach($input as $ent) { str_replace($ent[1], $ent[2], $ent[0]); } } $end = getmicrotime(); echo "str_replace took: ".($end - $start)."\n"; foreach($input as $key => $val) { $input[$key][1] = '!' . $val[1] . '!'; } $start = getmicrotime(); for ($i = 0; $i < 100000; $i++) { foreach($input as $ent) { preg_replace($ent[1], $ent[2], $ent[0]); } } $end = getmicrotime(); echo "preg_replace took: ".($end - $start)."\n"; foreach($input as $key => $val) { $input[$key][1] .= 'i'; } $start = getmicrotime(); for ($i = 0; $i < 100000; $i++) { foreach($input as $ent) { preg_replace($ent[1], $ent[2], $ent[0]); } } $end = getmicrotime(); echo "preg_replace(i) took: ".($end - $start)."\n"; ?>
-- PHP Development Mailing List <http://www.php.net/> To unsubscribe, visit: http://www.php.net/unsub.php