note 34934 added to function.in-array
| From: | morten at nilsen dot com | Date: | Tue, 12 Aug 2003 15:00:40 +0000 |
| Subject: | note 34934 added to function.in-array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-54014@lists.php.net to get a copy of this message | ||
either the benchmark I used, or the one used in an earlier comment is flawed, or this function has
seen great improvement...
on my system (a Duron 1GHz box) the following benchmark script gave me pretty close to
1 second execution time average when used with 355000 runs of in_array() (10 runs)
<?php
$average = 0;
for ($run=0;$run<10;++$run) {
$test_with=array(
1=>array(explode(":",
":1:2:3:4:5:6:7:8:9:10:11:12:13:14:15:")),
2=>array(explode(":",
":21:22:23:24:25:26:27:28:29:210:211:212:213:214:215:")),
3=>array(explode(":",
":14:15:23:24:25:26:27:28:29:210:211:212:213:214:215:"))
);
$start = microtime();
for($i=0;$i<=355000;++$i) { in_array($i, $test_with); }
$end = microtime();
$start = explode(" ",$start);
$end = explode(" ",$end);
$start = $start[1].trim($start[0],'0');
$end = $end[1].trim($end[0],'0');
$time = $end - $start;
$average += $time;
echo "run $run: $time<br>";
}
$average /= 10;
echo "average: $average";
?>
----
Manual Page -- http://www.php.net/manual/en/function.in-array.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+34934
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+34934&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+34934&report=yes