generated from Cadienvan/npm-package-ts-scaffolding
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbenchmark.js
41 lines (37 loc) · 1.12 KB
/
benchmark.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
const {cacheCandidate} = require('./dist');
const Benchmark = require('benchmark');
let suite = new Benchmark.Suite();
const normalFunction = function() {
return new Promise(function(resolve, reject) {
setTimeout(function() {
resolve(true);
}, 20);
});
};
const wrappedNFWithReqThreshold = cacheCandidate(normalFunction, {requestsThreshold: 1_000_000_000});
const wrappedNFWithCandidateFn = cacheCandidate(normalFunction, {candidateFunction: () => false});
suite.add('cacheCandidate OFF - normalFunction', {
defer: true,
fn: function (deferred) {
normalFunction().then(function() {
deferred.resolve();
});
}
}).add('cacheCandidate ON - Request Threshold unreachable', {
defer: true,
fn: function (deferred) {
wrappedNFWithReqThreshold().then(function() {
deferred.resolve();
});
}
}).add('cacheCandidate ON - Candidate Function set to false', {
defer: true,
fn: function (deferred) {
wrappedNFWithCandidateFn().then(function() {
deferred.resolve();
});
}
}).on('cycle', function(event) {
console.log(String(event.target));
})
.run({ 'async': true });