Skip to content

Commit d991874

Browse files
committed
Add Benchmarks
1 parent 83c6576 commit d991874

5 files changed

Lines changed: 77 additions & 95 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
**/*.rs.bk
33
bin/
44
pkg*/
5+
node_modules/

Cargo.lock

Lines changed: 25 additions & 75 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "base64-simd-wasm-vn"
33
description = "Base64 SIMD for WebAssembly"
4-
version = "1.1.1"
4+
version = "1.1.2"
55
edition = "2024"
66
repository = "https://github.com/ndtao2020/base64-simd-wasm-vn"
77
authors = ["Nguyen Dinh Tao <ndtao2020@gmail.com>"]
@@ -20,7 +20,6 @@ codegen-units = 1
2020
[dependencies]
2121
alloc_cat = "1"
2222
wasm-bindgen = "0.2"
23-
getrandom = { version = "0.2", default-features = false, features = ["js"] }
2423
base64-simd = { version = "0.8", default-features = false, features = [
2524
'alloc',
2625
] }

index.html

Lines changed: 48 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,61 @@
88

99
<body>
1010
<script type="module">
11-
import init, { encode, decode } from "./pkg/web/base64_simd_wasm_vn.js";
11+
import { Bench } from 'https://cdn.jsdelivr.net/npm/tinybench@6.0.0/dist/index.min.js'
12+
import init, { encode, decode, encodeUrlNoPad, decodeUrlNoPad } from "./pkg/web/base64_simd_wasm_vn.js";
1213

13-
const encoder = new TextEncoder();
14-
const decoder = new TextDecoder();
14+
const dataTXT = `
15+
To find information about a command, on the A-Z button menu at the top of this page, click the letter that the command starts with, and then click the command name.
16+
In addition to the tools installed with Windows XP, there are over 40 support tools included on the Windows XP CD. You can use these tools to diagnose and resolve computer problems.
17+
For more information about these support tools, see Windows Support Tools For information about installing support tools, see Install Windows Support Tools
18+
For more information about changes to the functionality of MS-DOS commands, new command-line tools, command shell functionality, configuring the command prompt,
19+
and automating commmand-line tasks, see Command-line reference
20+
Some command-line tools require the user to have administrator-level privileges on source and/or target computers.
21+
Command-line tools must be run at the prompt of the Cmd.exe command interpreter. To open Command Prompt, click Start, click Run, type cmd,
22+
and then click OK. To view help at the command-line, at the command prompt, type the following
23+
We're no longer updating this content regularly. Check the Microsoft Product Lifecycle for information about how this product, service, technology, or API is supported.
24+
`;
25+
const dataBytes = new TextEncoder().encode(dataTXT);
1526

16-
init().then(() => {
17-
const data = "SIMD-accelerated base64 encoding and decoding"
27+
// --- Init WASM once ---
28+
await init()
1829

19-
const encoded = encode(encoder.encode(data));
20-
const decoded = decode(encoded);
30+
// Tests
31+
const encoded = encode(dataBytes);
32+
const decoded = decode(encoded);
2133

22-
console.log("data: ", data);
23-
console.log("encode: ", encoded);
24-
console.log("decode: ", decoded);
34+
console.log("data: ", dataTXT);
35+
console.log("encode-simd: ", encoded);
36+
console.log("decode-simd: ", decoded);
37+
console.log("encode-web: ", btoa(dataTXT));
38+
console.log("decode-web: ", atob(encoded));
2539

26-
const text = decoder.decode(decoded)
40+
console.assert(new TextDecoder().decode(decoded) === dataTXT, "Base64 decode failed");
2741

28-
console.log("text: ", text);
42+
const encodedUrlNoPad = encodeUrlNoPad(dataBytes);
43+
const decodedUrlNoPad = decodeUrlNoPad(encodedUrlNoPad);
44+
45+
// --- Benchmark ---
46+
const bench = new Bench({
47+
name: 'base64 benchmark',
48+
time: 200,
49+
})
50+
51+
bench
52+
// STANDARD BASE64
53+
.add('base64-simd-wasm-vn encode', () => encode(dataBytes))
54+
.add('browser btoa encode', () => btoa(dataTXT))
55+
.add('base64-simd-wasm-vn decode', () => decode(encoded))
56+
.add('browser atob decode', () => atob(encoded))
57+
// BASE64 URL (NO PAD)
58+
.add('base64-simd-wasm-vn encodeUrlNoPad', () => encodeUrlNoPad(dataBytes))
59+
.add('base64-simd-wasm-vn decodeUrlNoPad', () => decodeUrlNoPad(encodedUrlNoPad));
60+
61+
await bench.run()
62+
63+
console.log(bench.name)
64+
console.table(bench.table())
2965

30-
if (data === text) {
31-
console.log('Ok !');
32-
}
33-
});
3466
</script>
3567
</body>
3668

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"ndtao2020"
66
],
77
"description": "Base64 SIMD for WebAssembly",
8-
"version": "1.1.1",
8+
"version": "1.1.2",
99
"license": "MIT License",
1010
"repository": {
1111
"type": "git",
@@ -76,4 +76,4 @@
7676
"webassembly",
7777
"vn"
7878
]
79-
}
79+
}

0 commit comments

Comments
 (0)