underscore vs no udnerscore

JavaScript performance comparison

Test case created by condition-vs-regex

Preparation code

<script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.4/underscore-min.js"></script>
<script>
Benchmark.prototype.setup = function() {
    var array = [
    {"name":"Joe", "age":17},
    {"name":"Bob", "age":17},
    {"name":"Carl", "age": 35},
    {"name":"Joe", "age":17},
    {"name":"Bob", "age":17},
    {"name":"Carl", "age": 35},
    {"name":"Joe", "age":17},
    {"name":"Bob", "age":17},
    {"name":"Carl", "age": 35},
    {"name":"Joe", "age":17},
    {"name":"Bob", "age":17},
    {"name":"Carl", "age": 35},
    {"name":"Joe", "age":17},
    {"name":"Bob", "age":17},
    {"name":"Carl", "age": 35},
    {"name":"Joe", "age":17},
    {"name":"Bob", "age":17},
    {"name":"Carl", "age": 35},
    {"name":"Joe", "age":17},
    {"name":"Bob", "age":17},
    {"name":"Carl", "age": 35},
    {"name":"Joe", "age":17},
    {"name":"Bob", "age":17},
    {"name":"Carl", "age": 35},
    {"name":"Joe", "age":17},
    {"name":"Bob", "age":17},
    {"name":"Carl", "age": 35},
    {"name":"Joe", "age":17},
    {"name":"Bob", "age":17},
    {"name":"Carl", "age": 35},
    {"name":"Joe", "age":17},
    {"name":"Bob", "age":17},
    {"name":"Carl", "age": 35}
    ];
};
</script>

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
underscore
console.log(_.chain(array).map(function(item) { return item.age }).uniq().value());
pending…
no underscore
var ages = array.map(function(obj) { return obj.age; });
ages = ages.filter(function(v,i) { return ages.indexOf(v) == i; });

console.log(ages); //=> [17, 35]
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