-
Notifications
You must be signed in to change notification settings - Fork 16
Move Criterion benches into separate benches crate
#306
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 |
|---|---|---|
| @@ -1,10 +1,10 @@ | ||
| [workspace] | ||
| resolver = "3" | ||
| members = [ | ||
| "ghash", | ||
| "poly1305", | ||
| "polyval" | ||
| ] | ||
| resolver = "2" | ||
|
|
||
| [patch.crates-io] | ||
| polyval = { path = "./polyval" } |
This file contains hidden or 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,24 @@ | ||
| [package] | ||
| name = "benches" | ||
| version = "0.0.0" | ||
| authors = ["RustCrypto Developers"] | ||
| license = "Apache-2.0 OR MIT" | ||
| description = "Criterion benchmarks of the universal-hashes crates" | ||
| edition = "2021" | ||
| publish = false | ||
|
|
||
| [workspace] | ||
|
|
||
| [dependencies] | ||
| polyval = { path = "../polyval/" } | ||
|
|
||
| criterion = "0.8" | ||
| criterion-cycles-per-byte = { version = "0.8", optional = true } | ||
|
|
||
| [features] | ||
| cpb = ["dep:criterion-cycles-per-byte"] | ||
|
|
||
| [[bench]] | ||
| name = "polyval" | ||
| path = "src/polyval.rs" | ||
| harness = false | ||
This file contains hidden or 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,10 @@ | ||
| # Criterion Benchmarks | ||
|
|
||
| This crate contains [`criterion`]-based benchmarks of the universal-hashes crates. | ||
|
|
||
| Supports cycles-per-byte benchmarks behind the `cpb` crate feature. | ||
| Read the [`criterion-cycles-per-byte`] docs for additional information | ||
| about supported targets and proper configuration of such measurements. | ||
|
|
||
| [`criterion`]: https://github.com/criterion-rs/criterion.rs | ||
| [`criterion-cycles-per-byte`]: https://github.com/criterion-rs/criterion-cycles-per-byte |
This file contains hidden or 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,31 @@ | ||
| //! POLYVAL benchmarks. | ||
| use criterion::{criterion_group, criterion_main, BenchmarkId, Throughput}; | ||
| use polyval::{universal_hash::UniversalHash, Polyval}; | ||
|
|
||
| mod utils; | ||
| use utils::{config, Benchmarker}; | ||
|
|
||
| fn bench(c: &mut Benchmarker) { | ||
| let mut group = c.benchmark_group("polyval"); | ||
|
|
||
| for size in &[10, 100, 1000, 10000] { | ||
| let buf = vec![0u8; *size]; | ||
|
|
||
| group.throughput(Throughput::Bytes(*size as u64)); | ||
|
|
||
| group.bench_function(BenchmarkId::new("update_padded", size), |b| { | ||
| let mut polyval = Polyval::new(&Default::default()); | ||
| b.iter(|| polyval.update_padded(&buf)); | ||
| }); | ||
| } | ||
|
|
||
| group.finish(); | ||
| } | ||
|
|
||
| criterion_group!( | ||
| name = benches; | ||
| config = config(); | ||
| targets = bench | ||
| ); | ||
|
|
||
| criterion_main!(benches); |
This file contains hidden or 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,17 @@ | ||
| use criterion::Criterion; | ||
|
|
||
| #[cfg(not(feature = "cpb"))] | ||
| pub type Benchmarker = Criterion; | ||
|
|
||
| #[cfg(feature = "cpb")] | ||
| pub type Benchmarker = Criterion<criterion_cycles_per_byte::CyclesPerByte>; | ||
|
|
||
| #[cfg(not(feature = "cpb"))] | ||
| pub fn config() -> Benchmarker { | ||
| Criterion::default() | ||
| } | ||
|
|
||
| #[cfg(feature = "cpb")] | ||
| pub fn config() -> Benchmarker { | ||
| Criterion::default().with_measurement(criterion_cycles_per_byte::CyclesPerByte) | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,31 +1,31 @@ | ||
| //! POLYVAL benchmarks. | ||
|
|
||
| #![allow(missing_docs)] | ||
| #![feature(test)] | ||
|
|
||
| use criterion::{BenchmarkId, Criterion, Throughput, criterion_group, criterion_main}; | ||
| use polyval::{Polyval, universal_hash::UniversalHash}; | ||
|
|
||
| fn bench(c: &mut Criterion) { | ||
| let mut group = c.benchmark_group("polyval"); | ||
|
|
||
| for size in &[10, 100, 1000, 10000] { | ||
| let buf = vec![0u8; *size]; | ||
|
|
||
| group.throughput(Throughput::Bytes(*size as u64)); | ||
| extern crate test; | ||
|
|
||
| group.bench_function(BenchmarkId::new("update_padded", size), |b| { | ||
| let mut polyval = Polyval::new(&Default::default()); | ||
| b.iter(|| polyval.update_padded(&buf)); | ||
| }); | ||
| } | ||
|
|
||
| group.finish(); | ||
| use polyval::{Polyval, universal_hash::UniversalHash}; | ||
| use test::Bencher; | ||
|
|
||
| // TODO(tarcieri): move this into the `universal-hash` crate | ||
| macro_rules! bench { | ||
| ($name:ident, $bs:expr) => { | ||
| #[bench] | ||
| fn $name(b: &mut Bencher) { | ||
| let key = Default::default(); | ||
| let mut m = Polyval::new(&key); | ||
| let data = [0; $bs]; | ||
|
|
||
| b.iter(|| { | ||
| m.update_padded(&data); | ||
| }); | ||
|
|
||
| b.bytes = $bs; | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| criterion_group!( | ||
| name = benches; | ||
| config = Criterion::default(); | ||
| targets = bench | ||
| ); | ||
|
|
||
| criterion_main!(benches); | ||
| bench!(bench_polyval_1_10, 10); | ||
| bench!(bench_polyval_2_100, 100); | ||
| bench!(bench_polyval_3_1000, 1000); | ||
| bench!(bench_polyval_4_10000, 10000); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should adapt this approach to other benchmark crates as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why? It can be completely automatic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO it looks really weird to switch measurements based on your target. Additionally, proper CPB measurement often requires additional setup as documented in the crate docs, so I think it's better to make this switch explicit.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's weird to opportunistically measure CPB where the feature is available. I think it's weird to have to turn it on when it could be automatic. Again, it's not something that's easily discoverable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By default you are likely to get low-quality data or failing bench. For example, on AMD x86 you should use RDPRU, which requires passing a separate flag and pinning your benchmark. On ARM you may need a whole separate dance.