Underscore _.object implementations

JavaScript performance comparison

Test case created by

Preparation code

<script src="http://documentcloud.github.com/underscore/underscore-min.js">
</script>
      
<script>
Benchmark.prototype.setup = function() {
  _.objectAlt = function(list, values) {
    if (list == null) return {};
    var pairs = values ? _.zip(list, _.take(values, list.length)) : list;
    return _.reduce(pairs, function(result, pair) {
      result[pair[0]] = pair[1];
      return result;
    }, {});
  };

};
</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
Current implementation, separate keys and values
_.object(["key1", "key2", "key3", "key4", "key5"], ["value1", "value2", "value3", "value4", "value5"]);
pending…
Alternative implementation, separate keys and values
_.objectAlt(["key1", "key2", "key3", "key4", "key5"], ["value1", "value2", "value3", "value4", "value5"]);
pending…
Current implementation, keys and values together
_.object([["key1", "value1"], ["key2", "value2"], ["key3", "value3"], ["key4", "value4"], ["key5", "value5"]]);
pending…
Alternative implementation, keys and values together
_.objectAlt([["key1", "value1"], ["key2", "value2"], ["key3", "value3"], ["key4", "value4"], ["key5", "value5"]]);
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