Skip to content

Instantly share code, notes, and snippets.

@aepyornis
Created October 6, 2015 17:27
Show Gist options
  • Save aepyornis/06147bc54f5583c49178 to your computer and use it in GitHub Desktop.
Save aepyornis/06147bc54f5583c49178 to your computer and use it in GitHub Desktop.
var async = require('async');
function big_calculation() {
var count = 0;
for (var i = 0; i < 100000; i++) {
for (var j = 0; j < 100000; j++) {
count += 1;
}
}
return count;
}
function sync_big_calculation() {
big_calculation();
big_calculation();
}
function parallel_big_calculation() {
async.parallel([
function(callback) {
big_calculation()
callback(null);
},
function(callback) {
big_calculation()
callback(null)
}
]);
}
console.time('big_calculation times two');
sync_big_calculation();
console.timeEnd('big_calculation times two');
console.time('with async-parallel');
parallel_big_calculation();
console.timeEnd('with async-parallel');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment