-
Notifications
You must be signed in to change notification settings - Fork 286
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add independent
regex_redux
benchmark test case (#1109)
* add independent regex_redux benchmark test case * exclude regex_redux benchmark crate in CI where needed
- Loading branch information
Showing
8 changed files
with
125 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[package] | ||
name = "wasmi_benches_regex_redux" | ||
version = "0.0.0" | ||
publish = false | ||
authors.workspace = true | ||
edition.workspace = true | ||
|
||
[lib] | ||
path = "lib.rs" | ||
crate-type = ["cdylib"] | ||
|
||
[dependencies] | ||
regex = "1.10.5" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
## Benchmark - Regex Redux | ||
|
||
Rust based `regex_redux` benchmark test case. | ||
|
||
Build with | ||
|
||
``` | ||
cargo build \ | ||
--package wasmi_benches_regex_redux \ | ||
--profile wasm \ | ||
--target wasm32-unknown-unknown | ||
``` | ||
|
||
Post-optimize with `wasm-opt` using: | ||
|
||
``` | ||
wasm-opt \ | ||
-O3 \ | ||
target/wasm32-unknown-unknown/wasm/wasmi_benches_regex_redux.wasm \ | ||
-o target/wasm32-unknown-unknown/wasm/wasmi_benches_regex_redux.opt.wasm | ||
``` | ||
|
||
Finally move the post-optimized Wasm binary into the proper place: | ||
|
||
``` | ||
cp \ | ||
target/wasm32-unknown-unknown/wasm/wasmi_benches_regex_redux.opt.wasm \ | ||
crates/wasmi/benches/rust/regex_redux.wasm | ||
``` | ||
|
||
Benchmark with: | ||
|
||
``` | ||
cargo bench --bench benches execute/regex_redux | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
//! Initially it was supposed to be like [1]. However it turned out | ||
//! that executing this code in Wasmi way too slow, unfortunately. | ||
//! | ||
//! [1]: https://benchmarksgame-team.pages.debian.net/benchmarksgame/program/regexredux-rust-2.html | ||
|
||
use regex::bytes::Regex; | ||
|
||
#[repr(C)] | ||
pub struct RegexReduxData { | ||
regex: Regex, | ||
input: Box<[u8]>, | ||
output: Option<usize>, | ||
} | ||
|
||
#[no_mangle] | ||
pub extern "C" fn setup(size: usize) -> Box<RegexReduxData> { | ||
Box::new(RegexReduxData { | ||
regex: Regex::new("agggtaa[cgt]|[acg]ttaccct").unwrap(), | ||
input: vec![0; size].into(), | ||
output: None, | ||
}) | ||
} | ||
|
||
#[no_mangle] | ||
pub extern "C" fn teardown(_: Box<RegexReduxData>) {} | ||
|
||
#[no_mangle] | ||
pub extern "C" fn input_ptr(data: &mut RegexReduxData) -> *mut u8 { | ||
data.input.as_mut_ptr() | ||
} | ||
|
||
#[no_mangle] | ||
pub extern "C" fn output(data: &mut RegexReduxData) -> u32 { | ||
match data.output { | ||
Some(output) => output.try_into().unwrap(), | ||
None => u32::MAX, | ||
} | ||
} | ||
|
||
#[no_mangle] | ||
pub extern "C" fn run(data: &mut RegexReduxData) { | ||
let result: usize = data.regex.find_iter(&data.input[..]).count(); | ||
data.output = Some(result); | ||
} |