| 26 | } |
| 27 | |
| 28 | function runAsync() { |
| 29 | // how many batches should we split the work in to? |
| 30 | var batches = process.argv[3] || 16; |
| 31 | var ended = 0; |
| 32 | var total = 0; |
| 33 | var start = Date.now(); |
| 34 | |
| 35 | function done (err, result) { |
| 36 | total += result; |
| 37 | |
| 38 | // have all the batches finished executing? |
| 39 | if (++ended === batches) { |
| 40 | printResult('Async', total / batches, Date.now() - start); |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | // for each batch of work, request an async Estimate() for |
| 45 | // a portion of the total number of calculations |
| 46 | for (var i = 0; i < batches; i++) { |
| 47 | addon.calculateAsync(calculations / batches, done); |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | runSync(); |
| 52 | runAsync(); |