underscore_mod-no-native (v16)

Revision 16 of this benchmark created by Alex on


Preparation HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/3.10.1/lodash.min.js"></script>
<script>
var lodash = _.noConflict();
</script>

Setup

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(); });

Test runner

Ready to run.

Testing in
TestOps/sec
each
var timesTwo = [];
numbers.forEach(function(num) { timesTwo.push(num * 2); });
ready
each lodash
var timesTwo = [];
lodash.each(numbers, function(num) { timesTwo.push(num * 2); });
ready
each object
var timesTwo = [];
for (var key in object) {
   if (!Object.prototype.hasOwnProperty.call(object, key)) continue;
   timesTwo.push(object[key] * 2); 
}

ready
each object lodash
var timesTwo = [];
lodash.each(object, function(num) { timesTwo.push(num * 2); });
ready
keys
Object.keys(object);
ready
keys lodash
lodash.keys(object);
ready
map
objects.map(function(obj) { return obj.num; });
ready
map lodash
lodash.map(objects, function(obj) { return obj.num; });
ready
pluck
Object.keys(objects).map(function(key){ return objects[key].num; });
ready
pluck lodash
lodash.pluck(objects, 'num');
ready
values
Object.keys(objects).map(function(key){ return objects[key]; });
ready
values lodash
lodash.values(objects);
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.