shimmed-vs-non-shimmed

JavaScript performance comparison

Revision 6 of this test case created

Info

Testing the performance of a lib like Underscore which will use shimmed methods vs one that will detect and avoid shimmed methods.

Preparation code

<script>
// simulate browsers without ES5 methods
(function() {
  var funcs = ['every', 'filter', 'forEach', 'indexOf', 'lastIndexOf', 'map', 'some', 'reduce', 'reduceRight'];
  Object.keys = null;
  for (var i = 0, l = funcs.length; i < l; i++) {
    Array.prototype[funcs[i]] = null;
  }
}());
</script>
<script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.4/underscore.js"></script>
<script>
var ub = _.noConflict();
</script>
<script src="//rawgithub.com/kriskowal/es5-shim/v2.1.0/es5-shim.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.4/underscore.js"></script>
<script>
var ua = _.noConflict();
</script>
<script src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/1.2.1/lodash.underscore.js"></script>
<script>
var lodash = _.noConflict();
</script>
<script>
Benchmark.prototype.setup = function() {
    var ub = window.ub,
        ua = window.ua,
        lodash = window.lodash;
   
    var numbers = Array(100);
    for (var i = 0; i < 100; i++) {
      numbers[i] = i;
    }
};
</script>

Preparation code output

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
_.each before shim
var doubles = [];
ub.each(numbers, function(num) { doubles.push(num * 2); });
pending…
_.each after shim
var doubles = [];
ua.each(numbers, function(num) { doubles.push(num * 2); });
pending…
lodash.each after shim
var doubles = [];
lodash.each(numbers, function(num) { doubles.push(num * 2); });
pending…
_.map before shim
var squares = ub.map(numbers, function(num) { return num * num; });
pending…
_.map after shim
var squares = ua.map(numbers, function(num) { return num * num; });
pending…
lodash.map after shim
var squares = lodash.map(numbers, function(num) { return num * num; });
pending…
_.filter before shim
var result = ub.filter(numbers, function(num) { return num % 2; });
pending…
_.filter after shim
var result = ua.filter(numbers, function(num) { return num % 2; });
pending…
lodash.filter after shim
var result = lodash.filter(numbers, function(num) { return num % 2; });
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. Here’s a list of current revisions for this page:

0 comments

Add a comment