Skip to content

Commit f71c8bf

Browse files
committed
Add Rust benchmarks for base64, sha512 and regex matching
1 parent 38799d3 commit f71c8bf

File tree

22 files changed

+270
-0
lines changed

22 files changed

+270
-0
lines changed

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,21 @@ You may find it useful to use [WebAssembly Binary Toolkit](https://github.com/We
2929
### .wat files
3030

3131
If you want to benchmark a specific instruction sequence, you can write a WebAssembly Text Format (.wat) file and compile it to Wasm with the wat2wasm tool from the [WebAssembly Binary Toolkit](https://github.com/WebAssembly/wabt).
32+
33+
## WebAssembly Rust Benchmarks (WasmRustBench)
34+
35+
This folder contains pre-compiled WebAssembly benchmarks written in Rust. Rust is currently a popular language to use for Wasm and allows using crates such as regex in Wasm benchmarks.
36+
37+
Install [Rust as per the instructions on their website](https://www.rust-lang.org/learn/get-started) and then install the wasm32-wasip1 target with:
38+
```bash
39+
rustup target add wasm32-wasip1
40+
```
41+
42+
To add a new benchmark, copy the `template` folder within the `sources` folder, set the package name in Cargo.toml to the name of your benchmark and add your benchmark code to `main` in `src/main.rs`.
43+
44+
Compile Rust with:
45+
```bash
46+
cargo build --release
47+
```
48+
49+
After compiling, copy the resulting `.wasm` file from the `target/wasm32-wasip1/release` folder into the `WasmRustBench` folder.

WasmRustBench/base64-bench.wasm

65.9 KB
Binary file not shown.
1.36 MB
Binary file not shown.

WasmRustBench/sha512-bench.wasm

60.8 KB
Binary file not shown.

WasmRustBench/sources/.gitignore

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Generated by Cargo
2+
# will have compiled files and executables
3+
debug
4+
target
5+
6+
# These are backup files generated by rustfmt
7+
**/*.rs.bk
8+
9+
# MSVC Windows builds of rustc generate these, which store debugging information
10+
*.pdb
11+
12+
# Generated by cargo mutants
13+
# Contains mutation testing data
14+
**/mutants.out*/
15+
16+
# RustRover
17+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
18+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
19+
# and can be added to the global gitignore or merged into this file. For a more nuclear
20+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
21+
#.idea/
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[build]
2+
target = "wasm32-wasip1"

WasmRustBench/sources/base64-bench/Cargo.lock

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[package]
2+
name = "base64-bench"
3+
version = "0.1.0"
4+
edition = "2024"
5+
6+
[dependencies]
7+
base64 = "0.22.1"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
use base64::{engine::general_purpose::STANDARD, Engine as _};
2+
3+
fn main() {
4+
for _n in 1..1000000 {
5+
let encoded = STANDARD.encode(b"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.");
6+
let _ = STANDARD.decode(encoded);
7+
}
8+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[build]
2+
target = "wasm32-wasip1"

0 commit comments

Comments
 (0)