Skip to content

Instantly share code, notes, and snippets.

@sagivo
Created June 2, 2016 19:05
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 sagivo/82a780702381a52e736f59a2f9d7cd63 to your computer and use it in GitHub Desktop.
Save sagivo/82a780702381a52e736f59a2f9d7cd63 to your computer and use it in GitHub Desktop.
benchmark of vs in
'use strict';
const timer = function(name) {
var start = new Date();
return {
stop: function() {
var end = new Date();
var time = end.getTime() - start.getTime();
console.log('Timer:', name, 'finished in', time, 'ms');
}
}
};
var a = [];
for (var i = 0; i < 1000000; i++) {
a.push(i);
}
let foo = 0;
var t = timer('using of');
for (const i of a) foo = i;
t.stop();
var t = timer('using in');
for (const i in a) foo = i;
t.stop();
@sagivo
Copy link
Author

sagivo commented Jun 2, 2016

Timer: using of finished in 61 ms
Timer: using in finished in 220 ms

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