Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Generated by Cargo
# will have compiled files and executables
debug
target

# These are backup files generated by rustfmt
**/*.rs.bk

# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb

# Generated by cargo mutants
# Contains mutation testing data
**/mutants.out*/

# RustRover
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,21 @@ You may find it useful to use [WebAssembly Binary Toolkit](https://github.com/We
### .wat files

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).

## WebAssembly Rust Benchmarks (WasmRustBench)

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.

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:
```bash
rustup target add wasm32-wasip1
```

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`.

Compile Rust with:
```bash
cargo build --release
```

After compiling, copy the resulting `.wasm` file from the `target/wasm32-wasip1/release` folder into the `WasmRustBench` folder.
Binary file added WasmRustBench/base64-bench.wasm
Binary file not shown.
Binary file added WasmRustBench/regex-match-bench.wasm
Binary file not shown.
Binary file added WasmRustBench/sha512-bench.wasm
Binary file not shown.
2 changes: 2 additions & 0 deletions WasmRustBench/sources/base64-bench/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[build]
target = "wasm32-wasip1"
16 changes: 16 additions & 0 deletions WasmRustBench/sources/base64-bench/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions WasmRustBench/sources/base64-bench/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "base64-bench"
version = "0.1.0"
edition = "2024"

[dependencies]
base64 = "0.22.1"
8 changes: 8 additions & 0 deletions WasmRustBench/sources/base64-bench/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use base64::{engine::general_purpose::STANDARD, Engine as _};

fn main() {
for _n in 1..1000000 {
let encoded = STANDARD.encode(b"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.");
let _ = STANDARD.decode(encoded);
}
}
2 changes: 2 additions & 0 deletions WasmRustBench/sources/regex-match-bench/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[build]
target = "wasm32-wasip1"
54 changes: 54 additions & 0 deletions WasmRustBench/sources/regex-match-bench/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions WasmRustBench/sources/regex-match-bench/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "regex-match-bench"
version = "0.1.0"
edition = "2024"

[dependencies]
regex = "1.11.1"
9 changes: 9 additions & 0 deletions WasmRustBench/sources/regex-match-bench/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use regex::Regex;

fn main() {
// https://html.spec.whatwg.org/multipage/input.html#valid-e-mail-address
let re = Regex::new(r"^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$").unwrap();
for _n in 1..1000000 {
re.is_match("a-zA-Z0-9.!#$%&'*+/=?^_`{|}[email protected]");
}
}
2 changes: 2 additions & 0 deletions WasmRustBench/sources/sha512-bench/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[build]
target = "wasm32-wasip1"
93 changes: 93 additions & 0 deletions WasmRustBench/sources/sha512-bench/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions WasmRustBench/sources/sha512-bench/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "sha512-bench"
version = "0.1.0"
edition = "2024"

[dependencies]
sha2 = "0.10.9"
7 changes: 7 additions & 0 deletions WasmRustBench/sources/sha512-bench/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use sha2::{Sha512, Digest};

fn main() {
for _n in 1..1000000 {
Sha512::digest(b"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.");
}
}
2 changes: 2 additions & 0 deletions WasmRustBench/sources/template/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[build]
target = "wasm32-wasip1"
7 changes: 7 additions & 0 deletions WasmRustBench/sources/template/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions WasmRustBench/sources/template/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[package]
name = "benchmark-template"
version = "0.1.0"
edition = "2024"
3 changes: 3 additions & 0 deletions WasmRustBench/sources/template/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
// Put your benchmark code here.
}
8 changes: 6 additions & 2 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def main():
args = parser.parse_args()

if args.suites == "all":
suites = ["SunSpider", "Kraken", "Octane", "JetStream", "JetStream3", "RegExp", "MicroBench", "WasmMicroBench"]
suites = ["SunSpider", "Kraken", "Octane", "JetStream", "JetStream3", "RegExp", "MicroBench", "WasmMicroBench", "WasmRustBench"]
else:
suites = args.suites.split(",")

Expand All @@ -64,17 +64,21 @@ def main():
for suite in suites:
results[suite] = {}
is_wasm_bench = suite == "WasmMicroBench"
is_wasm_rust_bench = suite == "WasmRustBench"

executable = ""
executable_arguments = []
if (is_wasm_bench):
executable = args.wasm_executable
executable_arguments = ["-e", "run_microbench"]
elif (is_wasm_rust_bench):
executable = args.wasm_executable
executable_arguments = ["-e", "_start", "-w"]
else:
executable = args.executable

for test_file in sorted(os.listdir(suite)):
if (is_wasm_bench):
if (is_wasm_bench or is_wasm_rust_bench):
if not test_file.endswith(".wasm"):
continue
else:
Expand Down