-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
4 changed files
with
278 additions
and
0 deletions.
There are no files selected for viewing
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
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!(); |
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,5 @@ | ||
fn main() { | ||
// Needed by tango benchmarks | ||
println!("cargo:rustc-link-arg-benches=-rdynamic"); | ||
println!("cargo:rerun-if-changed=build.rs"); | ||
} |