[dev] [cvs] commit: dimp/lib/Views ListMessages.php

Michael M Slusarz slusarz at horde.org
Thu Jun 26 19:08:00 UTC 2008


Quoting Michael M Slusarz <slusarz at horde.org>:

> slusarz     2008-06-26 14:58:40 EDT
>
>   Modified files:
>     lib/Views            ListMessages.php
>   Log:
>   Faster alternative to array_unique().
>
>   Revision  Changes    Path
>   1.76      +2 -2      dimp/lib/Views/ListMessages.php

For your viewing pleasure, the benchmark on the php.net array_unique()  
page run with the added keys-flip and keys only algorithm gives the  
following results on my machine (this is sorting an array of 50,000  
items with 10,000 unique elements):

0.014472961425781 (flip-flip)
0.015240907669067 (flip-flip-merge)
0.012692928314209 (keys-flip)
0.007965087890625 (keys only)
0.68577599525452 (array_unique)

In these tests, array_keys(array_flip()) is faster by approx 53x.  And  
changing the algorithm to store in keys from the beginning (if  
possible) and then doing array_keys() to get the unique list is approx  
86x faster.

michael

-- 
___________________________________
Michael Slusarz [slusarz at horde.org]



More information about the dev mailing list