UNPKG

1.22 kBJavaScriptView Raw
1const Whitelist = require('../lib/logasm/preprocessors/whitelist');
2
3let buildPointers = function(exactPointersCount, wildcardPointersCount) {
4 let pointers = [];
5
6 for (let index = 0; index < exactPointersCount; index++) {
7 pointers.push(`/exact${index}`);
8 }
9
10 for (let index = 0; index < wildcardPointersCount; index++) {
11 pointers.push(`/wildcard${index}/~`);
12 }
13
14 return pointers;
15};
16
17describe('Whitelist Performance', () =>
18
19 it('processes 10K statements for 100 exact and wildcard pointers with less than 100 milliseconds', function() {
20 let exactPointersCount = 100;
21 let wildcardPointersCount = 100;
22 let messagesToProcess = 10000;
23
24 let whitelist = new Whitelist({pointers: buildPointers(exactPointersCount, wildcardPointersCount)});
25
26 let startTimestamp = new Date();
27
28 for (let i = 0; i < messagesToProcess; i++) {
29 whitelist.process({
30 exact5: 'is',
31 exact40: 'this',
32 exact60: 'the',
33 wildcard5: {real: 'life'},
34 wildcard20: {is: 'this'},
35 secret: 'life'
36 });
37 }
38
39 let endTimestamp = new Date();
40 let duration = endTimestamp.getTime() - startTimestamp.getTime();
41
42 expect(duration).to.be.at.most(100);
43 })
44);