Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b0e6f10

Browse filesBrowse files
addaleaxMylesBorins
authored andcommitted
benchmark: add bench for zlib gzip + gunzip cycle
Originally wrote this for some work that is going to take a while longer before it’s ready to be PR’ed, so it seems fine to start with this on its own. PR-URL: #20034 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
1 parent 31812ed commit b0e6f10
Copy full SHA for b0e6f10

File tree

Expand file treeCollapse file tree

2 files changed

+46
-2
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+46
-2
lines changed
Open diff view settings
Collapse file

‎benchmark/zlib/pipe.js‎

Copy file name to clipboard
+39Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
'use strict';
2+
const common = require('../common.js');
3+
const fs = require('fs');
4+
const zlib = require('zlib');
5+
6+
const bench = common.createBenchmark(main, {
7+
inputLen: [1024],
8+
duration: [5],
9+
type: ['string', 'buffer']
10+
});
11+
12+
function main({ inputLen, duration, type }) {
13+
const buffer = Buffer.alloc(inputLen, fs.readFileSync(__filename));
14+
const chunk = type === 'buffer' ? buffer : buffer.toString('utf8');
15+
16+
const input = zlib.createGzip();
17+
const output = zlib.createGunzip();
18+
19+
let readFromOutput = 0;
20+
input.pipe(output);
21+
if (type === 'string')
22+
output.setEncoding('utf8');
23+
output.on('data', (chunk) => readFromOutput += chunk.length);
24+
25+
function write() {
26+
input.write(chunk, write);
27+
}
28+
29+
bench.start();
30+
write();
31+
32+
setTimeout(() => {
33+
// Give result in GBit/s, like the net benchmarks do
34+
bench.end(readFromOutput * 8 / (1024 ** 3));
35+
36+
// Cut off writing the easy way.
37+
input.write = () => {};
38+
}, duration * 1000);
39+
}
Collapse file

‎test/parallel/test-benchmark-zlib.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-benchmark-zlib.js
+7-2Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,10 @@ runBenchmark('zlib',
99
'method=deflate',
1010
'n=1',
1111
'options=true',
12-
'type=Deflate'
13-
]);
12+
'type=Deflate',
13+
'inputLen=1024',
14+
'duration=0.001'
15+
],
16+
{
17+
'NODEJS_BENCHMARK_ZERO_ALLOWED': 1
18+
});

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.