Skip to content

Commit

Permalink
Update parallel benchmarks (Promise + Compose)
Browse files Browse the repository at this point in the history
* Don't create object every time in Promise resolve
* Collect results in an array in Compose bench as it is dome
  in Promise.all
  • Loading branch information
lundibundi committed Apr 17, 2019
1 parent f3dd5c9 commit 4a2f71d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion tests/load/parallel.compose.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const testCompose = done => {
};

const f1 = metasync([[p1, p2, p3, p4, p5, p6]]);
f1(done);
f1([], done);
};

benchmark.do(COUNT, [testCompose]);
14 changes: 7 additions & 7 deletions tests/load/parallel.promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,25 @@ const benchmark = require('./benchmark.js');
const PromiseAll = done => {
let i = 0;
const p1 = new Promise(resolve => {
setImmediate(() => resolve({ p1: ++i * 2 }));
setImmediate(() => resolve(++i * 2));
});
const p2 = new Promise(resolve => {
setImmediate(() => resolve({ p2: ++i * 3 }));
setImmediate(() => resolve(++i * 3));
});
const p3 = new Promise(resolve => {
setImmediate(() => resolve({ p3: ++i * 5 }));
setImmediate(() => resolve(++i * 5));
});
const p4 = new Promise(resolve => {
setImmediate(() => resolve({ p4: 'key ' + ++i }));
setImmediate(() => resolve('key ' + ++i));
});
const p5 = new Promise(resolve => {
setImmediate(() => resolve({ p5: ++i === 5 }));
setImmediate(() => resolve(++i === 5));
});
const p6 = new Promise(resolve => {
setImmediate(() => resolve({ p6: 'key' + ++i * 2 }));
setImmediate(() => resolve('key' + ++i * 2));
});

Promise.all([p1, p2, p3, p4, p5, p6]).then(res => done(null, res));
Promise.all([p1, p2, p3, p4, p5, p6]).then(done.bind(null, null));
};

benchmark.do(COUNT, [PromiseAll]);

0 comments on commit 4a2f71d

Please sign in to comment.