Created
January 20, 2017 12:30
-
-
Save david-martin/051291a34d370b24708a915fa67ed1be to your computer and use it in GitHub Desktop.
This file contains hidden or 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
var async = require('async'); | |
var asyncStringify = require('async-json'); | |
var obj = require('./obj.json'); | |
var start = Date.now(); | |
for(var i=0,l=8; i<l; i++) { | |
JSON.stringify(obj); | |
} | |
console.log('sync stringify', Date.now() - start); | |
start = Date.now(); | |
async.times(8, function(i, next) { | |
// console.log('i outside', i, 'arguments', arguments.length); | |
asyncStringify.stringify(obj, function(err) { | |
if (err) throw err; | |
// console.log('i inside', i, 'arguments', arguments.length); | |
next(null, {}); | |
}); | |
}, function(err) { | |
if (err) throw err; | |
console.log('async stringify', Date.now() - start); | |
}) | |
// setTimeout(function() {}, 3000); | |
// var objMany = require('./obj-many.json'); | |
var objMany = {}; | |
for(var x = 0, y = 70000; x < y; x++) { | |
objMany['a' + x] = 'test'; | |
} | |
var start = Date.now(); | |
var i = 0; | |
for(var x in objMany) { | |
i++; | |
} | |
console.log('for each', i, Date.now() - start); | |
start = Date.now(); | |
var j = 0; | |
for(var x = 0, y = Object.keys(objMany).length; x < y; x++) { | |
j++; | |
} | |
console.log('for arr', j, Date.now() - start); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment