diff options
author | Florian Dold <florian@dold.me> | 2021-08-20 13:31:03 +0200 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2021-08-20 13:31:03 +0200 |
commit | 859a8734c87d5e5081d7b0aa02cb538a7c801eac (patch) | |
tree | d2e9163479eb56ec382c842d62ce39fe30d450a4 /test/2-perf.ts | |
download | node-vendor-859a8734c87d5e5081d7b0aa02cb538a7c801eac.tar.gz node-vendor-859a8734c87d5e5081d7b0aa02cb538a7c801eac.tar.bz2 node-vendor-859a8734c87d5e5081d7b0aa02cb538a7c801eac.zip |
Squashed 'fflate/' content from commit b786929
git-subtree-dir: fflate
git-subtree-split: b786929a368521e9cfcdcf7490a8e77485d5a253
Diffstat (limited to 'test/2-perf.ts')
-rw-r--r-- | test/2-perf.ts | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/test/2-perf.ts b/test/2-perf.ts new file mode 100644 index 0000000..98e0668 --- /dev/null +++ b/test/2-perf.ts @@ -0,0 +1,47 @@ +import { testSuites, workers, bClone, TestHandler } from './util'; +import { writeFileSync } from 'fs'; +import { join } from 'path'; + +const preprocessors = { + inflate: workers.zlib.deflate, + gunzip: workers.zlib.gzip, + unzlib: workers.zlib.zlib +}; + +const cache: Record<string, Record<string, Buffer>> = { + deflate: {}, + inflate: {}, + gzip: {}, + gunzip: {}, + zlib: {}, + unzlib: {} +}; + +const flattenedWorkers: Record<string, TestHandler> = {}; +for (const k in workers) { + for (const l in workers[k]) { + if (l == 'zip' || l == 'unzip') continue; + flattenedWorkers[k + '.' + l] = async (file, name, resetTimer) => { + const fileClone = bClone(file); + let buf = fileClone; + if (preprocessors[l]) { + buf = bClone(cache[l][name] ||= Buffer.from( + await preprocessors[l as keyof typeof preprocessors](buf, [buf.buffer]) + )); + resetTimer(); + } + const opt2 = preprocessors[l] + ? k === 'tinyInflate' + ? new Uint8Array(file.length) + : null + : { level: 1 }; + await workers[k][l]([buf, opt2], opt2 instanceof Uint8Array + ? [buf.buffer, opt2.buffer] + : [buf.buffer]); + } + } +} + +testSuites(flattenedWorkers).then(perf => { + writeFileSync(join(__dirname, 'results', 'timings.json'), JSON.stringify(perf, null, 2)); +});
\ No newline at end of file |