underscore_mod-no-native [latest versions 08.11.2015/]

JavaScript performance comparison

Revision 18 of this test case created by Maciej Trębacz

Preparation code

<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>
      
<script>
Benchmark.prototype.setup = function() {
  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(); });

};
</script>

Preparation code output

<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.4/lodash.js"></script> <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 object native
var timesTwo = [];
for (var key in object) {
   if (!Object.prototype.hasOwnProperty.call(object, key)) continue;
   timesTwo.push(object[key] * 2); 
}
pending…
pluck native
Object.keys(objects).map(function(key){ return objects[key].num; });
pending…
keys native
Object.keys(object);
pending…
values native
Object.keys(objects).map(function(key){ return objects[key]; });
pending…
map native
objects.map(function(obj) { return obj.num; });
pending…

Revisions

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

0 Comments