Forum Moderators: open
array = (
[0] => array (
country_code = 'DE',
country_name = 'Germany',
city_name = 'Munich'
),
[1] => array (
country_code = 'DE',
country_name = 'Germany',
city_name = 'Berlin'
),
[2] => array (
country_code = 'US',
country_name = 'United States',
city_name = 'New York'
),
);
I used two methods of sorting this dataset by subkey (e.g. "country_name"), one is a custom sort function:
var cfg_sortby_key = 'country_name';
function cSort(a, b) {
var y = a[cfg_sortby_key];
var x = b[cfg_sortby_key];
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
}
The other is an implementation of quicksort in javascript.
Here's the resultset of sorting 3300 rows on my PC (Intel Quadcore Q9540 @ 2.66 GHz, 4GB RAM using Windows Vista 64 bit)
Opera 9.52:
- sorting took 46 ms. using quicksort
- sorting took 32 ms. using custom sorting
FF 3.03:
- sorting took 40 ms. using quicksort
- sorting took 18 ms. using custom sorting
Safari 3.1.2:
- sorting took 84 ms. using quicksort
- sorting took 57 ms. using custom sorting
Google Chrome 0.2.149.30:
- sorting took 54 ms. using quicksort
- sorting took 84 ms. using custom sorting
IE 7.0.6001.18000
- sorting took 196 ms. using quicksort
- sorting took 298 ms. using custom sorting
Couldn't test out IE8 beta, since I cant get it to install on my system (something with a wups.dll error)
I was slightly disappointed by Google Chrome - didn't expect anything better off IE7. Other then that nothing spectacular, allthough it seems quicksort is not always as quick as people say it is...
What is good news is that the race is on to improve Javascript performance in future browser versions, an issue which is critical to the success of web applications but had previously been neglected by browser makers.