@cloudpss/compress 0.4.17 → 0.4.19
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 +12 -7
- package/package.json +5 -6
package/benchmark.js
CHANGED
|
@@ -15,7 +15,9 @@ 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) =>
|
|
18
|
+
const t = (/** @type {number} */ time) =>
|
|
19
|
+
Number.isFinite(time) ? (time.toFixed(2) + 'ms').padStart(10) : ' --------';
|
|
20
|
+
|
|
19
21
|
const pb = (/** @type {number} */ size) => prettyBytes(size, { binary: true });
|
|
20
22
|
|
|
21
23
|
await bokuwebZstd.init();
|
|
@@ -23,8 +25,9 @@ await bokuwebZstd.init();
|
|
|
23
25
|
/** 生成测试 */
|
|
24
26
|
function createTest(
|
|
25
27
|
/** @type {string} */ name,
|
|
26
|
-
/** @type {(value: Uint8Array) => Uint8Array} */ compressor,
|
|
27
|
-
/** @type {(value: Uint8Array) => Uint8Array} */ decompressor,
|
|
28
|
+
/** @type {((value: Uint8Array) => Uint8Array)} */ compressor,
|
|
29
|
+
/** @type {((value: Uint8Array) => Uint8Array)} */ decompressor,
|
|
30
|
+
/** @type {boolean} */ decompressOnly = false,
|
|
28
31
|
) {
|
|
29
32
|
/** 测试函数 */
|
|
30
33
|
function fn(/** @type {Buffer} */ data) {
|
|
@@ -35,7 +38,7 @@ function createTest(
|
|
|
35
38
|
const decompressed = decompressor(compressed);
|
|
36
39
|
const decompressTime = performance.now() - start;
|
|
37
40
|
console.assert(data.equals(decompressed), name, `unmatched`);
|
|
38
|
-
return { compressed, compressTime, decompressTime };
|
|
41
|
+
return { compressed, compressTime: decompressOnly ? NaN : compressTime, decompressTime };
|
|
39
42
|
}
|
|
40
43
|
Object.defineProperty(fn, 'name', { value: name });
|
|
41
44
|
return fn;
|
|
@@ -50,11 +53,11 @@ const tests = [
|
|
|
50
53
|
createTest('zstd -4 (O3,wasm)', (buf) => myZstdWasm.compress(buf, 4), myZstdWasm.decompress),
|
|
51
54
|
createTest('zstd -4 (cppzst)', (buf) => cppzst.compressSync(buf, { level: 4 }), cppzst.decompressSync),
|
|
52
55
|
createTest('zstd -4 (napi)', (buf) => myZstdNapi.compress(buf, 4), myZstdNapi.decompress),
|
|
53
|
-
createTest('zstd -4 (fzstd)', (buf) => myZstdNapi.compress(buf, 4), fzstd.decompress),
|
|
56
|
+
createTest('zstd -4 (fzstd)', (buf) => myZstdNapi.compress(buf, 4), fzstd.decompress, true),
|
|
54
57
|
createTest('zstd -10 (O3,wasm)', (buf) => myZstdWasm.compress(buf, 10), myZstdWasm.decompress),
|
|
55
58
|
createTest('zstd -10 (cppzst)', (buf) => cppzst.compressSync(buf, { level: 10 }), cppzst.decompressSync),
|
|
56
59
|
createTest('zstd -10 (napi)', (buf) => myZstdNapi.compress(buf, 10), myZstdNapi.decompress),
|
|
57
|
-
createTest('zstd -10 (fzstd)', (buf) => myZstdNapi.compress(buf, 10), fzstd.decompress),
|
|
60
|
+
createTest('zstd -10 (fzstd)', (buf) => myZstdNapi.compress(buf, 10), fzstd.decompress, true),
|
|
58
61
|
// 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
62
|
createTest('br -1 (wasm)', (buf) => brotli.compress(buf, { quality: 1 }), brotli.decompress),
|
|
60
63
|
// 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 +94,9 @@ for await (const { file, data } of files()) {
|
|
|
91
94
|
const compressed = result.compressed.length;
|
|
92
95
|
const ratio = (data.length / result.compressed.length).toFixed(2);
|
|
93
96
|
console.log(
|
|
94
|
-
` ${test.name.padEnd(
|
|
97
|
+
` ${test.name.padEnd(25)} ${ratio.padStart(6)} (${pb(compressed).padStart(8)}) ${t(
|
|
98
|
+
result.compressTime,
|
|
99
|
+
)} ${t(result.decompressTime)}`,
|
|
95
100
|
);
|
|
96
101
|
}
|
|
97
102
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudpss/compress",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.19",
|
|
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,19 +23,19 @@
|
|
|
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": {
|
|
31
30
|
"@bokuweb/zstd-wasm": "^0.0.20",
|
|
32
|
-
"@types/node": "^
|
|
31
|
+
"@types/node": "^20.1.7",
|
|
33
32
|
"@types/pako": "^2.0.0",
|
|
34
33
|
"@xingrz/cppzst": "^2.1.0-alpha.8",
|
|
35
34
|
"brotli-wasm": "^1.3.1",
|
|
36
35
|
"fzstd": "^0.1.0",
|
|
37
36
|
"pako": "^2.1.0",
|
|
38
37
|
"pretty-bytes": "^6.1.0",
|
|
39
|
-
"type-fest": "^3.
|
|
38
|
+
"type-fest": "^3.10.0",
|
|
40
39
|
"wasm-flate": "1.0.2"
|
|
41
40
|
}
|
|
42
41
|
}
|