underscore sort against native sort

JavaScript performance comparison

Test case created by rohit

Preparation code

<script src="http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.5.2/underscore-min.js"></script>

<script>

var labels = [{name: "elliot"}, {name: "steve"}, {name: "dhruv"}, {name: "guiga"}, {name: "rajat"}, {name: "rob"}];

function nativeSort() {
labels.sort(function(a, b) {
return a.name <= b.name ? -1 : 1;
});
}

function uSort() {
_(labels).sortBy(function(label) {
return label.name;
});
}

</script>

Preparation code output

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
native
function nativeSort() {
labels.sort(function(a, b) {
return a.name <= b.name ? -1 : 1;
});
}
pending…
underscore
function uSort() {
_(labels).sortBy(function(label) {
return label.name;
});
}
 
pending…

You can edit these tests or add even more tests to this page by appending /edit to the URL.

Compare results of other browsers

0 comments

Add a comment