Skip to content

Instantly share code, notes, and snippets.

@lahmatiy
Created June 20, 2014 09:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lahmatiy/d4d6316418fe349537dc to your computer and use it in GitHub Desktop.
Save lahmatiy/d4d6316418fe349537dc to your computer and use it in GitHub Desktop.
Native ES6 Promive vs. polyfill (https://github.com/lahmatiy/es6-promise-polyfill)
//
// Case 1
//
var a = [];
var t = performance.now();
for (var i = 0; i < 10000; i++)
a.push(new Promise(function(){}));
console.log(performance.now() - t);
//
// Case 2
//
var a = [];
var t = performance.now();
for (var i = 0; i < 10000; i++)
a.push(new Promise(function(r, rj){ a.push(r, rj) }));
console.log(performance.now() - t);
//
// Case 3
//
var a = [];
var rr = function(){};
var rj = function(){};
var t = performance.now();
for (var i = 0; i < 10000; i++)
{
var p = new Promise(function(r, rj){ a.push(r, rj) });
p.then(rr, rj);
a.push(p);
}
console.log(performance.now() - t);

Browsers

  • Chrome 35
  • Firefox 30
  • Internet Explorer 11

Case 1

  • Native
    • Chrome: 105ms / 1Mb
    • Firefox: 90ms
  • Polyfill
    • Chrome: 15ms / 320Kb
    • Firefox: 17ms
    • IE: 5.7ms / 680Kb

Case 2

  • Native
    • Chrome: 154ms / ~7.6Mb
    • Firefox: 113ms
  • Polyfill
    • Chrome 35: 18ms / 1.32Mb
    • Firefox: 25ms
    • IE: 6.4ms / 1.84Kb

Case 3

  • Native
    • Chrome: 162ms / ~10.5Mb
    • Firefox: 161ms
  • Polyfill
    • Chrome: 50ms / 2.7Mb
    • Firefox: 39ms
    • IE: 12ms / 2.84Kb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment