-
Notifications
You must be signed in to change notification settings - Fork 30.6k
/
Copy pathinflate.js
41 lines (38 loc) · 993 Bytes
/
inflate.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
'use strict';
const common = require('../common.js');
const zlib = require('zlib');
const bench = common.createBenchmark(main, {
method: ['inflate', 'inflateSync'],
inputLen: [1024],
n: [4e5],
});
function main({ n, method, inputLen }) {
// Default method value for tests.
method = method || 'inflate';
const chunk = zlib.deflateSync(Buffer.alloc(inputLen, 'a'));
let i = 0;
switch (method) {
// Performs `n` single inflate operations
case 'inflate': {
const inflate = zlib.inflate;
bench.start();
(function next(err, result) {
if (i++ === n)
return bench.end(n);
inflate(chunk, next);
})();
break;
}
// Performs `n` single inflateSync operations
case 'inflateSync': {
const inflateSync = zlib.inflateSync;
bench.start();
for (; i < n; ++i)
inflateSync(chunk);
bench.end(n);
break;
}
default:
throw new Error('Unsupported inflate method');
}
}