Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
function sync() {
var myData = '';
var DateObj = new Date();
for (var i=0; i<50000; i++) {
myData += "'" + DateObj.toString() +"', ";
}
return myData;
}
function async(DateObj, myData, i, cb) {
if (i === 50000)
return cb(null, myData);
myData += "'" + DateObj.toString() +"', ";
setImmediate(function() {
async(DateObj, myData, i + 1, cb);
});
}
console.time('sync');
var syncresult = sync();
console.timeEnd('sync');
console.time('async');
async(new Date(), '', 0, function(err, asyncresult) {
console.timeEnd('async');
console.log('Same result for both?', asyncresult === syncresult);
});
@amolmk

setImmediate(function() {
^
ReferenceError: setImmediate is not defined
at async (D:\New folder\app.js:14:1)
at Object. (D:\New folder\app.js:24:1)
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.runMain (module.js:492:10)
at process.startup.processNextTick.process._tickCallback (node.js:244:9)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.