Patryk Wychowaniec
Patryk Wychowaniec

Reputation: 346

PHP usort speed

At first, I'll give a link to code: http://ideone.com/6k8R6

On my Intel Core 2 Duo, PHP 5.4.6 result is:
usort: 7.8763520717621
quicksort: 2.9220938682556
(usort is slower than quicksort)

But on Ideone result is:
usort: 0.0313699245453
quicksort: 0.0621209144592
(usort is faster than quicksort)

I have also checked code at my friend's computer (Intel Core i5, PHP 5.4.4), and usort was also faster.

My question is: why sometimes quicksort is faster than usort and sometimes usort is faster?

Upvotes: 6

Views: 1932

Answers (1)

Ross Smith II
Ross Smith II

Reputation: 12189

Quicksort is considered one of the fastest sort algorithms on unsorted data, and the slowest on already sorted (or nearly sorted) data.

Upvotes: 1

Related Questions