fastest highest

JavaScript performance comparison

Test case created by Xotic750

Preparation code

<script src="http://underscorejs.org/underscore-min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

      
<script>
Benchmark.prototype.setup = function() {
  var articles = [],
      howMany = 50000,
      i = 0,
      article, highest;
  
  while (i < howMany) {
    article = {};
    article.text = "foobar";
    article.color = "red";
    article.number = i;
    articles.push(article);
    i += 1;
  }

};
</script>

Preparation code output

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

Test runner

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

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
while
hownMany = articles.length;
i = 0;
while (i < howMany) {
  if (typeof highest !== "number" || articles[i].number > highest) {
    highest = i;
  }

  i += 1;
}
pending…
sort pop
articles.sort(function(a, b) {
  return (a.number - b.number);
});

highest = articles.pop();
pending…
jquery each
$.each(articles, function(key, value) {
  if (value.number > highest) {
    highest = value.number;
  }
});
pending…
slice sort
highest = articles.slice(0).sort(function(x, y) {
  return y.number - x.number
})[0]
pending…
underscore
highest = articles.indexOf(_.max(articles, function(obj) {
  return obj.number;
}));
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.

0 Comments