underscore_mod-no-native [latest versions 08.11.2015/] (v18)

Revision 18 of this benchmark created by Maciej Trębacz on


Preparation HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.4/lodash.js"></script>

<script>
var lodash = _.noConflict();
</script>

Setup

var numbers = [];
  var object = {};
  for (var i = 0; i < 20; i++) {
    var random = Math.floor(Math.random() * 100);
    var random2 = Math.floor(Math.random() * 100);
    numbers[i] = random
    object['key' + random] = random2;
  }
  var objects = _.map(numbers, function(n) { return { 'num': n }; });
  var randomized = _.sortBy(numbers, function() { return Math.random(); });

Test runner

Ready to run.

Testing in
TestOps/sec
each object native
var timesTwo = [];
for (var key in object) {
   if (!Object.prototype.hasOwnProperty.call(object, key)) continue;
   timesTwo.push(object[key] * 2); 
}
ready
pluck native
Object.keys(objects).map(function(key){ return objects[key].num; });
ready
keys native
Object.keys(object);
ready
values native
Object.keys(objects).map(function(key){ return objects[key]; });
ready
map native
objects.map(function(obj) { return obj.num; });
ready

Revisions

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