sort-compare
JavaScript performance comparison
Info
Examining various algorithms for sorting non-strings.
Preparation code
<script>
function sort_1(el_1, el_2) {
if (el_1.name < el_2.name) return -1;
else if (el_1.name > el_2.name) return 1;
else return 0;
}
function sort_2(names) {
var orig_names = [].slice.call(names),
names_only = [],
i;
for (i = 0; i < orig_names.length; i++) {
names_only.push(orig_names[i].name + ":" + i);
}
names_only.sort();
for (i = 0; i < names_only.length; i++) {
names[i] = orig_names[~~ ((names_only[i].split(":"))[1])];
}
}
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
native sort with callback |
|
pending… |
native sort without callback |
|
pending… |
You can edit these tests or add even more tests to this page by appending /edit to the URL.
0 comments