Skip to content

Instantly share code, notes, and snippets.

@pingyen
Last active August 30, 2015 02:15
Show Gist options
  • Save pingyen/76686 to your computer and use it in GitHub Desktop.
Save pingyen/76686 to your computer and use it in GitHub Desktop.
JavaScript Function Call Performance Test
<html>
<head>
</head>
<body>
<script>
var i,
max = 10000000;
for(i = 0; i < max; ++i);
var t1 = (new Date).getTime();
var arr = [];
for(i = 0; i < max; ++i)
arr.push(i);
var t2 = (new Date).getTime();
var arr = [];
for(i = 0; i < max; ++i)
arr[arr.length] = i;
var t3 = (new Date).getTime();
document.write('first: ' + (t2 - t1) + ' second: ' + (t3 - t2));
</script>
</body>
</html>
@pingyen
Copy link
Author

pingyen commented May 11, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment