@cloudpss/compress 0.6.0-alpha.3 → 0.6.0-alpha.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudpss/compress",
3
- "version": "0.6.0-alpha.3",
3
+ "version": "0.6.0-alpha.4",
4
4
  "author": "CloudPSS",
5
5
  "license": "MIT",
6
6
  "type": "module",
package/benchmark.js DELETED
@@ -1,102 +0,0 @@
1
- /* eslint-disable no-console */
2
- import prettyBytes from 'pretty-bytes';
3
- import wasmFlate from 'wasm-flate';
4
- import zlib from 'zlib';
5
- import bokuwebZstd from '@bokuweb/zstd-wasm';
6
- import cppzst from '@xingrz/cppzst';
7
- import * as myZstdWasm from '@cloudpss/zstd/wasm';
8
- import * as myZstdNapi from '@cloudpss/zstd';
9
- import pako from 'pako';
10
- import * as fflate from 'fflate';
11
- import * as fzstd from 'fzstd';
12
- import files from '../../benchmark-files/index.js';
13
- import { createRequire } from 'node:module';
14
-
15
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
16
- const brotli = createRequire(import.meta.url)('brotli-wasm');
17
-
18
- const t = (/** @type {number} */ time) =>
19
- Number.isFinite(time) ? (time.toFixed(2) + 'ms').padStart(10) : ' --------';
20
-
21
- const pb = (/** @type {number} */ size) => prettyBytes(size, { binary: true });
22
-
23
- await bokuwebZstd.init();
24
-
25
- /** 生成测试 */
26
- function createTest(
27
- /** @type {string} */ name,
28
- /** @type {((value: Uint8Array) => Uint8Array)} */ compressor,
29
- /** @type {((value: Uint8Array) => Uint8Array)} */ decompressor,
30
- /** @type {boolean} */ decompressOnly = false,
31
- ) {
32
- /** 测试函数 */
33
- function fn(/** @type {Buffer} */ data) {
34
- let start = performance.now();
35
- const compressed = compressor(data);
36
- const compressTime = performance.now() - start;
37
- start = performance.now();
38
- const decompressed = decompressor(compressed);
39
- const decompressTime = performance.now() - start;
40
- console.assert(data.equals(decompressed), name, `unmatched`);
41
- return { compressed, compressTime: decompressOnly ? NaN : compressTime, decompressTime };
42
- }
43
- Object.defineProperty(fn, 'name', { value: name });
44
- return fn;
45
- }
46
- const tests = [
47
- createTest('gzip -d (wasm)', wasmFlate.gzip_encode_raw, wasmFlate.gzip_decode_raw),
48
- createTest('gzip -d (node)', zlib.gzipSync, zlib.gunzipSync),
49
- createTest('gzip -d (pako)', pako.gzip, pako.ungzip),
50
- createTest('gzip -d (fflate)', fflate.gzipSync, fflate.gunzipSync),
51
- createTest('zstd -3 (Oz,wasm)', (buf) => bokuwebZstd.compress(buf, 3), bokuwebZstd.decompress),
52
- createTest('zstd -3 (O3,wasm)', (buf) => myZstdWasm.compressSync(buf, 3), myZstdWasm.decompressSync),
53
- createTest('zstd -4 (O3,wasm)', (buf) => myZstdWasm.compressSync(buf, 4), myZstdWasm.decompressSync),
54
- createTest('zstd -4 (cppzst)', (buf) => cppzst.compressSync(buf, { level: 4 }), cppzst.decompressSync),
55
- createTest('zstd -4 (napi)', (buf) => myZstdNapi.compressSync(buf, 4), myZstdNapi.decompressSync),
56
- createTest('zstd -4 (fzstd)', (buf) => myZstdNapi.compressSync(buf, 4), fzstd.decompress, true),
57
- createTest('zstd -10 (O3,wasm)', (buf) => myZstdWasm.compressSync(buf, 10), myZstdWasm.decompressSync),
58
- createTest('zstd -10 (cppzst)', (buf) => cppzst.compressSync(buf, { level: 10 }), cppzst.decompressSync),
59
- createTest('zstd -10 (napi)', (buf) => myZstdNapi.compressSync(buf, 10), myZstdNapi.decompressSync),
60
- createTest('zstd -10 (fzstd)', (buf) => myZstdNapi.compressSync(buf, 10), fzstd.decompress, true),
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
62
- createTest('br -1 (wasm)', (buf) => brotli.compress(buf, { quality: 1 }), brotli.decompress),
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
64
- createTest('br -3 (wasm)', (buf) => brotli.compress(buf, { quality: 3 }), brotli.decompress),
65
- createTest(
66
- 'br -3 (node)',
67
- (buf) =>
68
- zlib.brotliCompressSync(buf, {
69
- params: { [zlib.constants.BROTLI_PARAM_QUALITY]: 3 },
70
- }),
71
- zlib.brotliDecompressSync,
72
- ),
73
- createTest(
74
- `br -5 (node)`,
75
- (buf) =>
76
- zlib.brotliCompressSync(buf, {
77
- params: { [zlib.constants.BROTLI_PARAM_QUALITY]: 5 },
78
- }),
79
- zlib.brotliDecompressSync,
80
- ),
81
- createTest(
82
- `br -8 (node)`,
83
- (buf) =>
84
- zlib.brotliCompressSync(buf, {
85
- params: { [zlib.constants.BROTLI_PARAM_QUALITY]: 8 },
86
- }),
87
- zlib.brotliDecompressSync,
88
- ),
89
- ];
90
- for await (const { file, data } of files()) {
91
- console.log(`File: ${file} \tRaw: ${pb(data.length)}`);
92
- for (const test of tests) {
93
- const result = test(data);
94
- const compressed = result.compressed.length;
95
- const ratio = (data.length / result.compressed.length).toFixed(2);
96
- console.log(
97
- ` ${test.name.padEnd(25)} ${ratio.padStart(6)} (${pb(compressed).padStart(8)}) ${t(
98
- result.compressTime,
99
- )} ${t(result.decompressTime)}`,
100
- );
101
- }
102
- }
package/jest.config.js DELETED
@@ -1,3 +0,0 @@
1
- import { config } from '../jest.config.js';
2
-
3
- export default { ...config };