Skip to content

Commit 4352dab

Browse files
authored
Merge pull request #43 from danleh/zlib-wasm
Add zlib-wasm workload
2 parents df8f146 + f66a045 commit 4352dab

File tree

10 files changed

+3989
-1
lines changed

10 files changed

+3989
-1
lines changed

JetStreamDriver.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2147,7 +2147,20 @@ const BENCHMARKS = [
21472147
},
21482148
async: true,
21492149
testGroup: WasmGroup
2150-
})
2150+
}),
2151+
// zlib-wasm
2152+
new WasmEMCCBenchmark({
2153+
name: "zlib-wasm",
2154+
files: [
2155+
"./wasm/zlib/build/zlib.js",
2156+
"./wasm/zlib/benchmark.js",
2157+
],
2158+
preload: {
2159+
wasmBinary: "./wasm/zlib/build/zlib.wasm",
2160+
},
2161+
iterations: 40,
2162+
testGroup: WasmGroup
2163+
}),
21512164
];
21522165

21532166
// LuaJSFight tests

wasm-cli.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ testList = [
3535
"argon2-wasm",
3636
"argon2-wasm-simd",
3737
"8bitbench-wasm",
38+
"zlib-wasm",
3839
];
3940

4041
// Reuse the full CLI runner, just with the subset of Wasm line items above.

wasm/zlib/benchmark.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright 2025 the V8 project authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
class Benchmark {
6+
async runIteration() {
7+
if (!Module._main)
8+
await setupModule(Module);
9+
10+
Module.FS.writeFile('input', Module.wasmBinary);
11+
12+
const inputStr = Module.stringToNewUTF8('input');
13+
const inputzStr = Module.stringToNewUTF8('input.z');
14+
const inputzoutStr = Module.stringToNewUTF8('input.z.out');
15+
16+
for (let i = 0; i < 10; i++) {
17+
Module._compressFile(inputStr, inputzStr);
18+
Module._decompressFile(inputzStr, inputzoutStr);
19+
if (Module.FS.stat('input').size !== Module.FS.stat('input.z.out').size) {
20+
throw new Error("Length after decompression doesn't match");
21+
}
22+
}
23+
24+
Module._free(inputzoutStr);
25+
Module._free(inputzStr);
26+
Module._free(inputStr);
27+
}
28+
29+
validate() {
30+
const input = Module.FS.readFile('input');
31+
const outputRoundtrip = Module.FS.readFile('input.z.out');
32+
for (let i = 0; i < input.length; i++) {
33+
if (input[i] !== outputRoundtrip[i]) {
34+
throw new Error("Content after decompression doesn't match at offset " + i);
35+
}
36+
}
37+
}
38+
}

wasm/zlib/build.log

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Built on 2025-02-12T12:38:44Z
2+
Toolchain versions
3+
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.73 (ac676d5e437525d15df5fd46bc2c208ec6d376a3)
4+
Getting zpipe.c example source...
5+
Building...
6+
Building done

wasm/zlib/build.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
rm -rf build/
6+
rm -f src/zpipe.c
7+
8+
touch build.log
9+
BUILD_LOG="$(realpath build.log)"
10+
echo "Built on $(date -u '+%Y-%m-%dT%H:%M:%SZ')" | tee "$BUILD_LOG"
11+
12+
echo "Toolchain versions" | tee -a "$BUILD_LOG"
13+
emcc --version | head -n1 | tee -a "$BUILD_LOG"
14+
15+
echo "Getting zpipe.c example source..." | tee -a "$BUILD_LOG"
16+
curl -o "src/zpipe.c" https://www.zlib.net/zpipe.c
17+
18+
echo "Building..." | tee -a "$BUILD_LOG"
19+
mkdir build/
20+
emcc -o build/zlib.js \
21+
-s WASM=1 -O2 \
22+
-g1 --emit-symbol-map \
23+
-s USE_ZLIB=1 -s FORCE_FILESYSTEM=1 \
24+
-s MODULARIZE=1 -s EXPORT_NAME=setupModule -s EXPORTED_RUNTIME_METHODS=FS,stringToNewUTF8 -s EXPORTED_FUNCTIONS=_compressFile,_decompressFile,_free \
25+
src/zpipe.c src/main.c | tee -a "$BUILD_LOG"
26+
# If you want the native build for reference:
27+
# clang -o build/zlib -O2 -lz src/zpipe.c src/main.c
28+
29+
echo "Building done" | tee -a "$BUILD_LOG"
30+
ls -lth build/

0 commit comments

Comments
 (0)