// generate an array of 1000 elements
var a = new Array(1000).join(",.").split(","),
calls = 0;
// call sort method incrementing the conter
a.sort(function(a, b){
++calls;
// return zero, nothing should change
return 0;
});
// discover the monster
alert(calls);
Guess how many times Internet Explorer compare results? 17583 times, against a.length - 1 in other browsers.
Nice stuff guys, I guess for big arrays a manual reimplementation could perform better, am I wrong?
No comments:
Post a Comment