public
Created

  • Download Gist
test.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
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);
});

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)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.