-
-
Save einaros/9be3d411baa7e8443254 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var runs = 0; | |
function exec() { | |
runs += this.y / 1337; | |
} | |
var x = { | |
y: 1337, | |
a: [1], | |
go1: function() { | |
for (var i = 0, al = this.a.length; i < al; ++i) { | |
exec.apply(this); | |
} | |
}, | |
go2: function() { | |
this.a.forEach(exec.bind(this)); | |
}, | |
go3: function() { | |
for (var i = 0; i < this.a.length; ++i) { | |
exec.apply(this); | |
} | |
}, | |
} | |
d = Date.now(); | |
for (var a = 0, l = 1024 * 1024; a < l; ++a) x.go1(); | |
console.log('for', Date.now() - d); | |
d = Date.now(); | |
for (g = 0, gl = 1024 * 1024; g < gl; ++g) x.go1(); | |
console.log('for, global iterator', Date.now() - d); | |
d = Date.now(); | |
for (var a = 0, l = 1024 * 1024; a < l; ++a) x.go3(); | |
console.log('for, no length caching', Date.now() - d); | |
d = Date.now(); | |
for (var a = 0, l = 1024 * 1024; a < l; ++a) x.go2(); | |
console.log('foreach', Date.now() - d); |
for 89
for, global iterator 112
for, no length caching 90
foreach 526
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
for 91
for, global iterator 106
foreach 481