I have this bit of code with node.js.
I want to make 2 parallel task and I don't care in what order they finish. In the end both will insert something in a database, but I must do some calculations and some string replacement first.
Is it normal that my test function always finish first when I run this bit ?
I execute the code 10-20 times and test always finish before test2.
async.parallel([
function (callback) {
v2 = test(200);
callback(null, v2);
},
function (callback) {
v3 = test2(300);
callback(null, v3);
}
], function (err, results) {
console.log(results)
});
My test function here will have like 2-3 nested for loops, will count a lot of information in memory.
function test(a) {
for (var i = 0; i < 1000000; i++) {
a = a + 1;
}
console.log('Finished 1');
return a + 100;
}
This function should finish first because there is only one operations in it...
function test2(a) {
console.log('Finished 2');
return a + 200;
}