Created
October 6, 2015 17:27
-
-
Save aepyornis/06147bc54f5583c49178 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'); | |
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