native sort vs underscore sortBy

JavaScript performance comparison

Revision 5 of this test case created by austin

Preparation code

<script src="http://documentcloud.github.com/underscore/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() {
    _.sortBy(labels, 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 sort
nativeSort();
pending…
underscore sortBy
uSort();
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment