-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PR-URL: #13322 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
- Loading branch information
Showing
7 changed files
with
482 additions
and
360 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
'use strict'; | ||
var common = require('../common.js'); | ||
var zlib = require('zlib'); | ||
|
||
var bench = common.createBenchmark(main, { | ||
type: [ | ||
'Deflate', 'DeflateRaw', 'Inflate', 'InflateRaw', 'Gzip', 'Gunzip', 'Unzip' | ||
], | ||
options: ['true', 'false'], | ||
n: [5e5] | ||
}); | ||
|
||
function main(conf) { | ||
var n = +conf.n; | ||
var fn = zlib['create' + conf.type]; | ||
if (typeof fn !== 'function') | ||
throw new Error('Invalid zlib type'); | ||
var i = 0; | ||
|
||
if (conf.options === 'true') { | ||
var opts = {}; | ||
bench.start(); | ||
for (; i < n; ++i) | ||
fn(opts); | ||
bench.end(n); | ||
} else { | ||
bench.start(); | ||
for (; i < n; ++i) | ||
fn(); | ||
bench.end(n); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
'use strict'; | ||
var common = require('../common.js'); | ||
var zlib = require('zlib'); | ||
|
||
var bench = common.createBenchmark(main, { | ||
method: ['createDeflate', 'deflate', 'deflateSync'], | ||
inputLen: [1024], | ||
n: [4e5] | ||
}); | ||
|
||
function main(conf) { | ||
var n = +conf.n; | ||
var method = conf.method; | ||
var chunk = Buffer.alloc(+conf.inputLen, 'a'); | ||
|
||
var i = 0; | ||
switch (method) { | ||
// Performs `n` writes for a single deflate stream | ||
case 'createDeflate': | ||
var deflater = zlib.createDeflate(); | ||
deflater.resume(); | ||
deflater.on('finish', () => { | ||
bench.end(n); | ||
}); | ||
|
||
bench.start(); | ||
(function next() { | ||
if (i++ === n) | ||
return deflater.end(); | ||
deflater.write(chunk, next); | ||
})(); | ||
break; | ||
// Performs `n` single deflate operations | ||
case 'deflate': | ||
var deflate = zlib.deflate; | ||
bench.start(); | ||
(function next(err, result) { | ||
if (i++ === n) | ||
return bench.end(n); | ||
deflate(chunk, next); | ||
})(); | ||
break; | ||
// Performs `n` single deflateSync operations | ||
case 'deflateSync': | ||
var deflateSync = zlib.deflateSync; | ||
bench.start(); | ||
for (; i < n; ++i) | ||
deflateSync(chunk); | ||
bench.end(n); | ||
break; | ||
default: | ||
throw new Error('Unsupported deflate method'); | ||
} | ||
} |
Oops, something went wrong.