-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathperf.js
60 lines (42 loc) · 1.33 KB
/
perf.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
'use strict';
var hpp = require('../../lib/index.js');
var present = require('present');
describe('Performance', function () {
it('for checking body with two middleware including whitelist', function () {
this.timeout(10000); // CI build might be very slow
var firstMiddleware = hpp();
var secondMiddleware = hpp({
whitelist: [ 'filter' ]
});
var simulateRequest = function (req) {
firstMiddleware(req, {}, function () {
secondMiddleware(req, {}, function () {});
});
};
var timeStart = present();
var req;
var iterations = 100000;
for ( var i = 0; i < iterations; i+=1 ) {
req = {
query: {
name: 'John',
last: 'Doe',
age: 33,
filter: [ 'a', 'b' ]
}
};
simulateRequest(req);
}
var timeEnd = present();
expect(req).to.eql({
query: {
name: 'John',
last: 'Doe',
age: 33,
filter: [ 'a', 'b' ]
},
queryPolluted: {}
});
console.log('Processing a single requests took ' + ((timeEnd - timeStart) / iterations) + 'ms');
});
});