Underscore unique vs. imperitive

JavaScript performance comparison

Test case created by Jeremy Elbourn

Preparation code

<script src="http://underscorejs.org/underscore-min.js"></script>
 
<script>
Benchmark.prototype.setup = function() {
    var x = [{path: 'fileNameGoesHere'}, {path: 'fileNameGoesHere'}, {path: 'fileNameGoesHere'}, {path: 'fileNameGoesHere'}, {path: 'blue'}, {path: 'fileNameGoesHere'}];
    var hide = [];
};
</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
functional
if (_.chain(x).pluck('path').unique().size().value() <= 1) {
    hide.push('path');
  }
pending…
imperitive
  if (x.length <= 1) {
    hide.push('path');
  } else {
    var firstPath = _.first(x).path || '';
    var allSame = _.all(x, function(xi) {
      return xi.path === firstPath;
    });

    if (allSame) {
      hide.push('path');
    }
  }
 
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