Created
May 9, 2010 22:31
-
-
Save JosephPecoraro/395472 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// So this will run in a browser as well as a shell. | |
if (this.window) { | |
window.print = function(s) { console.log(s); } | |
} | |
var TOTAL = 1e5; | |
var row = 0; | |
var data = { | |
rows: [{ a: "hi", b: 1, c: true, d: "wah!" }] | |
}; | |
print('expected: ' + TOTAL*3); | |
// Test without caching property lookups | |
(function() { | |
var start = Date.now(); | |
var count = 0; | |
for (var i=0; i<TOTAL; ++i) | |
for (var item in data['rows'][row]) | |
if (typeof data['rows'][row][item] === 'string' || typeof data['rows'][row][item] === 'number') | |
count++; | |
var end = Date.now(); | |
print('count: ' + count); | |
print(end-start+'ms'); | |
})(); | |
// Test with caching property lookups | |
(function() { | |
var start = Date.now(); | |
var count = 0; | |
for (var i=0; i<TOTAL; ++i) { | |
var theRow = data.rows[row]; | |
for (var itemName in theRow) { | |
var item = theRow[itemName]; | |
if (typeof item === 'string' || typeof item === 'number') | |
count++; | |
} | |
} | |
var end = Date.now(); | |
print('count: ' + count); | |
print(end-start+'ms'); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment