Skip to content

Commit

Permalink
benchmarks: add 'stringzilla'
Browse files Browse the repository at this point in the history
  • Loading branch information
BurntSushi committed Feb 24, 2024
1 parent cedf318 commit 328df56
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 0 deletions.
1 change: 1 addition & 0 deletions .vim/coc-settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"benchmarks/engines/rust-memchrold/Cargo.toml",
"benchmarks/engines/rust-sliceslice/Cargo.toml",
"benchmarks/engines/rust-std/Cargo.toml",
"benchmarks/engines/stringzilla/Cargo.toml",
"benchmarks/shared/Cargo.toml",
"fuzz/Cargo.toml",
"Cargo.toml"
Expand Down
20 changes: 20 additions & 0 deletions benchmarks/engines.toml
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,26 @@
bin = "cargo"
args = ["clean"]

# Engines based on the `stringzilla` library.
#
# See: https://github.com/ashvardanian/StringZilla

[[engine]]
name = "stringzilla/memmem/oneshot"
cwd = "./engines/stringzilla"
[engine.version]
bin = "./target/release/main"
args = ["--version"]
[engine.run]
bin = "./target/release/main"
args = ["memmem-oneshot"]
[[engine.build]]
bin = "cargo"
args = ["build", "--release"]
[[engine.clean]]
bin = "cargo"
args = ["clean"]

# Engines based on the Rust standard library.

[[engine]]
Expand Down
63 changes: 63 additions & 0 deletions benchmarks/engines/stringzilla/Cargo.lock

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

23 changes: 23 additions & 0 deletions benchmarks/engines/stringzilla/Cargo.toml
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"
39 changes: 39 additions & 0 deletions benchmarks/engines/stringzilla/main.rs
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)))
})
}

0 comments on commit 328df56

Please sign in to comment.