Skip to content

Commit

Permalink
Add tango-based benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
qsantos committed Oct 18, 2024
1 parent bdd61c5 commit 68de2ac
Show file tree
Hide file tree
Showing 4 changed files with 278 additions and 0 deletions.
204 changes: 204 additions & 0 deletions Cargo.lock

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

5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,16 @@ rust-version = "1.74.1"
[dev-dependencies]
criterion = { version = "0.5.1", features = ["html_reports"] }
rand = "0.8.5"
tango-bench = "0.6.0"

[[bench]]
name = "criterion"
harness = false

[[bench]]
name = "tango"
harness = false

[profile.profiling]
inherits = "release"
debug = true
Expand Down
64 changes: 64 additions & 0 deletions benches/tango.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
use std::io::Seek;

use std::hint::black_box;
use tango_bench::{benchmark_fn, tango_benchmarks, tango_main, IntoBenchmarks};

use ripmors::*;

fn ascii_benchmarks() -> impl IntoBenchmarks {
[
benchmark_fn("encode_string_ascii", |b| {
let data = std::fs::read_to_string("1-original.txt").unwrap();
b.iter(move || encode_string_ascii(black_box(data.as_bytes())))
}),
benchmark_fn("encode_stream_ascii", |b| {
let mut f = std::fs::File::open("1-original.txt").unwrap();
let mut devnull = std::fs::File::create("/dev/null").unwrap();
b.iter(move || {
f.rewind().unwrap();
encode_stream_ascii(&mut f, &mut devnull).unwrap();
})
}),
]
}

fn unicode_benchmarks() -> impl IntoBenchmarks {
[
benchmark_fn("encode_string_unicode", |b| {
let data = std::fs::read_to_string("4-unicode.txt").unwrap();
b.iter(move || encode_string(black_box(&data)))
}),
benchmark_fn("encode_stream_unicode", |b| {
let mut f = std::fs::File::open("4-unicode.txt").unwrap();
let mut devnull = std::fs::File::create("/dev/null").unwrap();
b.iter(move || {
f.rewind().unwrap();
encode_stream(&mut f, &mut devnull).unwrap();
})
}),
]
}

fn decode_benchmarks() -> impl IntoBenchmarks {
[
benchmark_fn("decode_string", |b| {
let data = std::fs::read_to_string("2-encoded.txt").unwrap();
b.iter(move || decode_string(black_box(&data.as_bytes()), to_standard))
}),
benchmark_fn("decode_stream", |b| {
let mut f = std::fs::File::open("2-encoded.txt").unwrap();
let mut devnull = std::fs::File::create("/dev/null").unwrap();
b.iter(move || {
f.rewind().unwrap();
encode_stream(&mut f, &mut devnull).unwrap();
})
}),
]
}

tango_benchmarks!(
ascii_benchmarks(),
unicode_benchmarks(),
decode_benchmarks()
);
tango_main!();
5 changes: 5 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
fn main() {
// Needed by tango benchmarks
println!("cargo:rustc-link-arg-benches=-rdynamic");
println!("cargo:rerun-if-changed=build.rs");
}

0 comments on commit 68de2ac

Please sign in to comment.