underscore_mod-no-native

JavaScript performance comparison

Revision 16 of this test case created by Alex

Preparation code

<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/3.10.1/lodash.min.js"></script>
<script>
var lodash = _.noConflict();
</script>
      
<script>
Benchmark.prototype.setup = function() {
  var numbers = [];
  var object = {};
  for (var i = 0; i < 20; i++) {
    numbers[i] = i;
    object['key' + i] = i;
  }
  var objects = lodash.map(numbers, function(n) { return { 'num': n }; });
  var randomized = lodash.sortBy(numbers, function() { return Math.random(); });

};
</script>

Preparation code output

<script> var lodash = _.noConflict(); </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
each
var timesTwo = [];
numbers.forEach(function(num) { timesTwo.push(num * 2); });
pending…
each lodash
var timesTwo = [];
lodash.each(numbers, function(num) { timesTwo.push(num * 2); });
pending…
each object
var timesTwo = [];
for (var key in object) {
   if (!Object.prototype.hasOwnProperty.call(object, key)) continue;
   timesTwo.push(object[key] * 2); 
}

pending…
each object lodash
var timesTwo = [];
lodash.each(object, function(num) { timesTwo.push(num * 2); });
pending…
keys
Object.keys(object);
pending…
keys lodash
lodash.keys(object);
pending…
map
objects.map(function(obj) { return obj.num; });
pending…
map lodash
lodash.map(objects, function(obj) { return obj.num; });
pending…
pluck
Object.keys(objects).map(function(key){ return objects[key].num; });
pending…
pluck lodash
lodash.pluck(objects, 'num');
pending…
values
Object.keys(objects).map(function(key){ return objects[key]; });
pending…
values lodash
lodash.values(objects);
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