-
-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cedf318
commit 328df56
Showing
5 changed files
with
146 additions
and
0 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
[package] | ||
publish = false | ||
name = "main" | ||
version = "3.3.0" # should match 'stringzilla' version below | ||
edition = "2021" | ||
|
||
[workspace] | ||
|
||
[dependencies] | ||
anyhow = "1.0.72" | ||
stringzilla = "3.3.0" | ||
|
||
[dependencies.shared] | ||
path = "../../shared" | ||
|
||
[[bin]] | ||
name = "main" | ||
path = "main.rs" | ||
|
||
[profile.release] | ||
debug = true | ||
codegen-units = 1 | ||
lto = "fat" |
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,39 @@ | ||
use std::io::Write; | ||
|
||
use shared::{Benchmark, Sample}; | ||
|
||
use stringzilla::StringZilla; | ||
|
||
fn main() -> anyhow::Result<()> { | ||
let Some(arg) = std::env::args_os().nth(1) else { | ||
anyhow::bail!("Usage: runner (<engine-name> | --version)") | ||
}; | ||
let Ok(arg) = arg.into_string() else { | ||
anyhow::bail!("argument given is not valid UTF-8") | ||
}; | ||
if arg == "--version" { | ||
writeln!(std::io::stdout(), env!("CARGO_PKG_VERSION"))?; | ||
return Ok(()); | ||
} | ||
let engine = arg; | ||
let b = Benchmark::from_stdin()?; | ||
let samples = match (&*engine, &*b.model) { | ||
("memmem-oneshot", "count") => memmem_oneshot_count(&b)?, | ||
(engine, model) => { | ||
anyhow::bail!("unrecognized engine '{engine}' and model '{model}'") | ||
} | ||
}; | ||
let mut stdout = std::io::stdout().lock(); | ||
for s in samples.iter() { | ||
writeln!(stdout, "{},{}", s.duration.as_nanos(), s.count)?; | ||
} | ||
Ok(()) | ||
} | ||
|
||
fn memmem_oneshot_count(b: &Benchmark) -> anyhow::Result<Vec<Sample>> { | ||
let haystack = &b.haystack; | ||
let needle = b.one_needle()?; | ||
shared::run(b, || { | ||
Ok(shared::count_memmem(haystack, needle, |h, n| h.sz_find(n))) | ||
}) | ||
} |