Skip to content

Instantly share code, notes, and snippets.

@os0x
Forked from katsuma/performance.js
Created October 23, 2012 00:40
Show Gist options
  • Save os0x/3935916 to your computer and use it in GitHub Desktop.
Save os0x/3935916 to your computer and use it in GitHub Desktop.
(function() {
var max = 10000;
var pi = Math.PI;
(function() {
var a = new Array(max);
console.time('native');
for (var i = 0, len = a.length; i < len; i++) {
a[i] = pi;
};
console.timeEnd('native');
})();
(function() {
var b = new Array(max);
console.time('each');
$.each(b, function(k, v) {
b[k] = pi;
});
console.timeEnd('each');
})();
})();
// Use http://code.jquery.com/jquery-1.8.2.min.js
// native: 0.425ms
// each: 3.330ms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment