Skip to content

Commit

Permalink
Reduce test suite to decompression benchmarks, average 10 runs
Browse files Browse the repository at this point in the history
  • Loading branch information
karyon committed Aug 21, 2023
1 parent 4b0f6bb commit 0fdbfd1
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 43 deletions.
20 changes: 10 additions & 10 deletions test/0-valid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ import * as assert from 'uvu/assert';
// to prevent infinite loops from hanging the process.
testSuites({
async compression(file) {
const fileClone = bClone(file);
const cProm = workers.fflate.deflate(fileClone, [fileClone.buffer]);
cProm.timeout(10000);
const buf = await cProm;
assert.ok(file.equals(await workers.zlib.inflate(buf, [buf.buffer])));
// const fileClone = bClone(file);
// const cProm = workers.fflate.deflate(fileClone, [fileClone.buffer]);
// cProm.timeout(10000);
// const buf = await cProm;
// assert.ok(file.equals(await workers.zlib.inflate(buf, [buf.buffer])));
},
async decompression(file) {
const fileClone = bClone(file);
const data = await workers.zlib.deflate(fileClone, [fileClone.buffer]);
const dProm = workers.fflate.inflate(data, [data.buffer]);
dProm.timeout(5000);
assert.ok(file.equals(await dProm));
// const fileClone = bClone(file);
// const data = await workers.zlib.deflate(fileClone, [fileClone.buffer]);
// const dProm = workers.fflate.inflate(data, [data.buffer]);
// dProm.timeout(5000);
// assert.ok(file.equals(await dProm));
}
});
1 change: 1 addition & 0 deletions test/1-size.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const sizePerf: Record<string, Record<string, [number, number]>> = {};

testSuites({
async main(file, name) {
return;
sizePerf[name] = {};
for (const lib of (['fflate', 'pako', 'uzip', 'zlib'] as const)) {
const clone = bClone(file);
Expand Down
8 changes: 4 additions & 4 deletions test/2-perf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { writeFileSync } from 'fs';
import { join } from 'path';

const preprocessors = {
inflate: workers.zlib.deflate,
gunzip: workers.zlib.gzip,
unzlib: workers.zlib.zlib
inflate: workers.fflate.deflate,
gunzip: workers.fflate.gzip,
unzlib: workers.fflate.zlib
};

const cache: Record<string, Record<string, Buffer>> = {
Expand All @@ -20,7 +20,7 @@ const cache: Record<string, Record<string, Buffer>> = {
const flattenedWorkers: Record<string, TestHandler> = {};
for (const k in workers) {
for (const l in workers[k]) {
if (l == 'zip' || l == 'unzip') continue;
if (l == 'zip' || l == 'unzip' || l == 'deflate' || l == 'gzip' || l == 'zlib') continue;
flattenedWorkers[k + '.' + l] = async (file, name, resetTimer) => {
const fileClone = bClone(file);
let buf = fileClone;
Expand Down
63 changes: 34 additions & 29 deletions test/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,16 @@ export const testSuites = async <T extends Record<string, TestHandler>, D extend
const localPerf = {} as Record<DK, number>;
for (const name in tf) {
ste(name, async () => {
let ts = performance.now();
await suites[k](localTestFiles[name], name, () => {
ts = performance.now();
});
localPerf[name] = performance.now() - ts;
localPerf[name] = 0;
const NUM_ITERATIONS = 10;
for (let i = 0; i < NUM_ITERATIONS; i++) {
let ts = performance.now();
await suites[k](localTestFiles[name], name, () => {
ts = performance.now();
});
localPerf[name] += performance.now() - ts;
}
localPerf[name] /= NUM_ITERATIONS;
});
}
ste.after(() => {
Expand Down Expand Up @@ -162,32 +167,32 @@ export const workers = {
gunzip: wc(fflate, 'gunzipSync'),
zlib: wc(fflate, 'zlibSync'),
unzlib: wc(fflate, 'unzlibSync'),
zip: wc(fflate, 'zipSync'),
// zip: wc(fflate, 'zipSync'),
unzip: wc(fflate, 'unzipSync')
},
pako: {
deflate: wc('pako', 'deflateRaw'),
inflate: wc('pako', 'inflateRaw'),
gzip: wc('pako', 'gzip'),
gunzip: wc('pako', 'ungzip'),
zlib: wc('pako', 'deflate'),
unzlib: wc('pako', 'inflate')
},
uzip: {
deflate: wc('uzip', 'deflateRaw'),
inflate: wc('uzip', 'inflateRaw')
},
tinyInflate: {
inflate: wc('tiny-inflate')
},
zlib: {
deflate: wc('zlib', 'deflateRawSync'),
inflate: wc('zlib', 'inflateRawSync'),
gzip: wc('zlib', 'gzipSync'),
gunzip: wc('zlib', 'gunzipSync'),
zlib: wc('zlib', 'deflateSync'),
unzlib: wc('zlib', 'inflateSync')
}
// pako: {
// deflate: wc('pako', 'deflateRaw'),
// inflate: wc('pako', 'inflateRaw'),
// gzip: wc('pako', 'gzip'),
// gunzip: wc('pako', 'ungzip'),
// zlib: wc('pako', 'deflate'),
// unzlib: wc('pako', 'inflate')
// },
// uzip: {
// deflate: wc('uzip', 'deflateRaw'),
// inflate: wc('uzip', 'inflateRaw')
// },
// tinyInflate: {
// inflate: wc('tiny-inflate')
// },
// zlib: {
// deflate: wc('zlib', 'deflateRawSync'),
// inflate: wc('zlib', 'inflateRawSync'),
// gzip: wc('zlib', 'gzipSync'),
// gunzip: wc('zlib', 'gunzipSync'),
// zlib: wc('zlib', 'deflateSync'),
// unzlib: wc('zlib', 'inflateSync')
// }
};

export const bClone = (buf: Buffer) => {
Expand Down

0 comments on commit 0fdbfd1

Please sign in to comment.