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