@cloudpss/compress 0.4.17 → 0.4.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/benchmark.js +9 -7
- package/package.json +3 -4
package/benchmark.js
CHANGED
|
@@ -15,7 +15,8 @@ import { createRequire } from 'node:module';
|
|
|
15
15
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
16
16
|
const brotli = createRequire(import.meta.url)('brotli-wasm');
|
|
17
17
|
|
|
18
|
-
const t = (/** @type {number} */ time) => (time.toFixed(2) + 'ms').padStart(
|
|
18
|
+
const t = (/** @type {number} */ time) => (Number.isFinite(time) ? (time.toFixed(2) + 'ms').padStart(10) : ' --------');
|
|
19
|
+
|
|
19
20
|
const pb = (/** @type {number} */ size) => prettyBytes(size, { binary: true });
|
|
20
21
|
|
|
21
22
|
await bokuwebZstd.init();
|
|
@@ -23,8 +24,9 @@ await bokuwebZstd.init();
|
|
|
23
24
|
/** 生成测试 */
|
|
24
25
|
function createTest(
|
|
25
26
|
/** @type {string} */ name,
|
|
26
|
-
/** @type {(value: Uint8Array) => Uint8Array} */ compressor,
|
|
27
|
-
/** @type {(value: Uint8Array) => Uint8Array} */ decompressor,
|
|
27
|
+
/** @type {((value: Uint8Array) => Uint8Array)} */ compressor,
|
|
28
|
+
/** @type {((value: Uint8Array) => Uint8Array)} */ decompressor,
|
|
29
|
+
/** @type {boolean} */ decompressOnly = false,
|
|
28
30
|
) {
|
|
29
31
|
/** 测试函数 */
|
|
30
32
|
function fn(/** @type {Buffer} */ data) {
|
|
@@ -35,7 +37,7 @@ function createTest(
|
|
|
35
37
|
const decompressed = decompressor(compressed);
|
|
36
38
|
const decompressTime = performance.now() - start;
|
|
37
39
|
console.assert(data.equals(decompressed), name, `unmatched`);
|
|
38
|
-
return { compressed, compressTime, decompressTime };
|
|
40
|
+
return { compressed, compressTime: decompressOnly ? NaN : compressTime, decompressTime };
|
|
39
41
|
}
|
|
40
42
|
Object.defineProperty(fn, 'name', { value: name });
|
|
41
43
|
return fn;
|
|
@@ -50,11 +52,11 @@ const tests = [
|
|
|
50
52
|
createTest('zstd -4 (O3,wasm)', (buf) => myZstdWasm.compress(buf, 4), myZstdWasm.decompress),
|
|
51
53
|
createTest('zstd -4 (cppzst)', (buf) => cppzst.compressSync(buf, { level: 4 }), cppzst.decompressSync),
|
|
52
54
|
createTest('zstd -4 (napi)', (buf) => myZstdNapi.compress(buf, 4), myZstdNapi.decompress),
|
|
53
|
-
createTest('zstd -4 (fzstd)', (buf) => myZstdNapi.compress(buf, 4), fzstd.decompress),
|
|
55
|
+
createTest('zstd -4 (fzstd)', (buf) => myZstdNapi.compress(buf, 4), fzstd.decompress, true),
|
|
54
56
|
createTest('zstd -10 (O3,wasm)', (buf) => myZstdWasm.compress(buf, 10), myZstdWasm.decompress),
|
|
55
57
|
createTest('zstd -10 (cppzst)', (buf) => cppzst.compressSync(buf, { level: 10 }), cppzst.decompressSync),
|
|
56
58
|
createTest('zstd -10 (napi)', (buf) => myZstdNapi.compress(buf, 10), myZstdNapi.decompress),
|
|
57
|
-
createTest('zstd -10 (fzstd)', (buf) => myZstdNapi.compress(buf, 10), fzstd.decompress),
|
|
59
|
+
createTest('zstd -10 (fzstd)', (buf) => myZstdNapi.compress(buf, 10), fzstd.decompress, true),
|
|
58
60
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-argument
|
|
59
61
|
createTest('br -1 (wasm)', (buf) => brotli.compress(buf, { quality: 1 }), brotli.decompress),
|
|
60
62
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-argument
|
|
@@ -91,7 +93,7 @@ for await (const { file, data } of files()) {
|
|
|
91
93
|
const compressed = result.compressed.length;
|
|
92
94
|
const ratio = (data.length / result.compressed.length).toFixed(2);
|
|
93
95
|
console.log(
|
|
94
|
-
` ${test.name.padEnd(
|
|
96
|
+
` ${test.name.padEnd(25)} ${ratio.padStart(6)} (${pb(compressed).padStart(8)}) ${t(result.compressTime)} ${t(result.decompressTime)}`,
|
|
95
97
|
);
|
|
96
98
|
}
|
|
97
99
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudpss/compress",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.18",
|
|
4
4
|
"author": "CloudPSS",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -12,8 +12,7 @@
|
|
|
12
12
|
"default": "./dist/index.js"
|
|
13
13
|
},
|
|
14
14
|
"browser": {
|
|
15
|
-
"./dist/gzip/index.js": "./dist/gzip/index-browser.js"
|
|
16
|
-
"./dist/zstd/index.js": "./dist/zstd/index-browser.js"
|
|
15
|
+
"./dist/gzip/index.js": "./dist/gzip/index-browser.js"
|
|
17
16
|
},
|
|
18
17
|
"scripts": {
|
|
19
18
|
"start": "yarn clean && tsc --watch",
|
|
@@ -24,7 +23,7 @@
|
|
|
24
23
|
"benchmark": "node ./benchmark"
|
|
25
24
|
},
|
|
26
25
|
"dependencies": {
|
|
27
|
-
"@cloudpss/zstd": "^0.2.
|
|
26
|
+
"@cloudpss/zstd": "^0.2.7",
|
|
28
27
|
"fflate": "^0.7.4"
|
|
29
28
|
},
|
|
30
29
|
"devDependencies": {
|