Skip to content

Instantly share code, notes, and snippets.

@hmaurer
Forked from Constellation/t078.js
Created December 9, 2012 00: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 hmaurer/4242805 to your computer and use it in GitHub Desktop.
Save hmaurer/4242805 to your computer and use it in GitHub Desktop.
function t1() {
var ary = [];
for (var i = 0; i < 10000000; ++i) {
ary[i] = i;
}
return ary;
}
function t2() {
var ary = [];
var i = 10000000;
while (i--) {
ary[i] = i;
}
return ary;
}
var now = Date.now();
t1();
print(Date.now() - now);
var now = Date.now();
t2();
print(Date.now() - now);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment