Skip to content

Commit

Permalink
Merge pull request #11415 from Uzlopak/improve-validation-benchmark
Browse files Browse the repository at this point in the history
chore: add async benchmarks for validate
  • Loading branch information
vkarpov15 committed Feb 21, 2022
2 parents c39fb46 + a227f40 commit 7d6c7bb
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions benchmarks/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,30 @@ const goodBreakfast = new Breakfast({

// const time = (new Date - start) / 1000;
// console.error('took %d seconds for %d docs (%d dps)', time, total, total / time);
new Benchmark.Suite()
.add('invalid', function () {
badBreakfast.validateSync();
})
.add('valid', function () {
goodBreakfast.validateSync();
})
const suite = new Benchmark.Suite()
suite
.add('invalid async', {
'defer': true,
'fn': function (deferred) {
// avoid test inlining
suite.name;
badBreakfast.validate().catch(() => deferred.resolve())
},
})
.add('valid async', {
'defer': true,
'fn': function (deferred) {
// avoid test inlining
suite.name;
goodBreakfast.validate().then(() => deferred.resolve())
},
})
.add('invalid sync', function () {
badBreakfast.validateSync();
})
.add('valid sync', function () {
goodBreakfast.validateSync();
})
.on('cycle', function (evt) {
if (process.env.MONGOOSE_DEV || process.env.PULL_REQUEST) {
console.log(String(evt.target));
Expand Down

0 comments on commit 7d6c7bb

Please sign in to comment.