note 98500 added to function.array-unique
| From: | michieledthalentnl at osu1 dot php dot net | Date: | Fri, 18 Jun 2010 23:50:45 +0000 |
| Subject: | note 98500 added to function.array-unique | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-170255@lists.php.net to get a copy of this message | ||
Then what is even faster is using array_flip.
<?php
$max = 1000000;
$arr = range(1,$max,3);
$arr2 = range(1,$max,2);
$arr = array_merge($arr,$arr2);
$time = -microtime(true);
$res1 = array_unique($arr);
$time += microtime(true);
echo "deduped to ".count($res1)." in ".$time;
// deduped to 666667 in 13.498242855072
$time = -microtime(true);
$res2 = array();
$res2 = array_flip($arr);
$res2 = array_keys($res2);
$time += microtime(true);
echo "<br />deduped to ".count($res2)." in ".$time;
// deduped to 666667 in 0.37050104141235
$time = -microtime(true);
$res3 = array();
foreach($arr as $key=>$val) {
$res3[$val] = true;
}
$res3 = array_keys($res3);
$time += microtime(true);
echo "<br />deduped to ".count($res3)." in ".$time;
// deduped to 666667 in 0.54348206520081
?>
----
Server IP: 91.199.167.223
Probable Submitter: 85.145.30.83
----
Manual Page -- http://www.php.net/manual/en/function.array-unique.php
Edit -- https://master.php.net/note/edit/98500
Del: integrated -- https://master.php.net/note/delete/98500/integrated
Del: useless -- https://master.php.net/note/delete/98500/useless
Del: bad code -- https://master.php.net/note/delete/98500/bad+code
Del: spam -- https://master.php.net/note/delete/98500/spam
Del: non-english -- https://master.php.net/note/delete/98500/non-english
Del: in docs -- https://master.php.net/note/delete/98500/in+docs
Del: other reasons-- https://master.php.net/note/delete/98500
Reject -- https://master.php.net/note/reject/98500
Search -- https://master.php.net/manage/user-notes.php