Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions benchmark/zlib/createInflate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
'use strict';
const common = require('../common.js');
const zlib = require('zlib');

const bench = common.createBenchmark(main, {
inputLen: [16 * 1024 * 1024],
chunkLen: [1024],
n: [1e2]
});

function main({ n, inputLen, chunkLen }) {
const input = zlib.deflateSync(Buffer.alloc(inputLen, 'a'));

let i = 0;
bench.start();
(function next() {
let p = 0;
const inflater = zlib.createInflate();
inflater.resume();
inflater.on('finish', () => {
if (i++ === n)
return bench.end(n);
next();
});

(function nextChunk() {
if (p >= input.length)
return inflater.end();
inflater.write(input.slice(p, p += chunkLen), nextChunk);
})();
})();
}
37 changes: 37 additions & 0 deletions benchmark/zlib/inflate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
'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 }) {
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');
}
}
5 changes: 4 additions & 1 deletion common.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,10 @@
'RuntimeLibrary': '<(MSVC_runtimeType)',
'RuntimeTypeInfo': 'false',
}
}
},
'xcode_settings': {
'GCC_OPTIMIZATION_LEVEL': '3', # stop gyp from defaulting to -Os
},
}
},

Expand Down
Loading