Skip to content

Instantly share code, notes, and snippets.

@stagas
Created September 8, 2010 10:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stagas/569941 to your computer and use it in GitHub Desktop.
Save stagas/569941 to your computer and use it in GitHub Desktop.
var myarray = []
for (var i=0; i<5000000; i++) {
myarray.push(i)
}
var time, newTime, wlen=0, wlength=0
for (var y=0; y<20; y++) {
time = new Date()
for (var x=0; x<10; x++) {
for (var i=0; i<myarray.length; i++) {
}
}
newTime = new Date()
wlength += newTime - time
time = new Date()
for (var x=0; x<10; x++) {
for (var i=0, len=myarray.length; i<len; i++) {
}
}
newTime = new Date()
wlen += newTime - time
}
console.log('With var len: ' + (wlen/20))
console.log('With .length: ' + (wlength/20))
With var len: 195.65
With .length: 263.75
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment