-
Notifications
You must be signed in to change notification settings - Fork 33
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
hash bench #77
hash bench #77
Conversation
@bobbinth let me know if there is anything to be done for this PR to get it merged on v0.3 :) |
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.
Thank you! I left some small comment inline.
I guess the bigger question is whether these show results which are any different from what we have here. If so, we'll need to figure out what to understand what drives the discrepancy and potentially re-run the benchmarks on various platforms to update the table.
benches/hash.rs
Outdated
) | ||
}); | ||
for size in BATCH_SIZES { | ||
let v: Vec<Felt> = (0..size).map(|_| rand_value::<Felt>()).collect(); |
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 not use rand_vector()
function here?
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.
changed to rand_vector
benches/hash.rs
Outdated
let v: Vec<Felt> = (0..size).map(|_| rand_value::<Felt>()).collect(); | ||
|
||
group.bench_with_input( | ||
BenchmarkId::new(format!("RPO256/{size}"), size), |
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 doing /{size}
is redundant here. We could probably just do: BenchmarkId::new("RPO256", size)
.
benches/hash.rs
Outdated
); | ||
|
||
group.bench_with_input( | ||
BenchmarkId::new(format!("Blake3/256/{size}"), size), |
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 doing /{size}
is redundant here. We could probably just do: BenchmarkId::new("Blake3_256", size)
.
benches/hash.rs
Outdated
static BATCH_SIZES: [usize; 8] = [ | ||
2usize.pow(0), | ||
2usize.pow(1), | ||
2usize.pow(2), | ||
2usize.pow(3), | ||
2usize.pow(4), | ||
2usize.pow(5), | ||
2usize.pow(6), | ||
2usize.pow(7), | ||
]; |
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.
We probably don't need as many batches. I'd probably do the following:
static BATCH_SIZES: [usize; 8] = [
16,
32,
64,
100,
256,
];
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.
changed
benches/hash.rs
Outdated
[Blake3_256::hash(&[1_u8]), Blake3_256::hash(&[2_u8])]; | ||
c.bench_function("Blake3 2-to-1 hashing (cached)", |bench| { | ||
bench.iter(|| Blake3_256::merge(black_box(&v))) | ||
group.bench_with_input(BenchmarkId::new("Blake3/256", 1), &s2, |b, i| { |
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.
nit: I'd change benchmark ID to: BenchmarkId::new("Blake3_256", 1)
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.
changed all /
to _
// Benchmark `merge` in a hot loop with varying number of elements, the goal is to spend more | ||
// time in the hashing function so that the cost of measuring it will dissipiate in the | ||
// background and give better view of the algorithms performance. | ||
for size in BATCH_SIZES { |
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 it is fine if we test it on just a couple of sizes - e.g, 64 and 256.
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.
This request conflicts with the one above: https://github.com/0xPolygonMiden/crypto/pull/77/files#r1156632675
I kept the list above. Let me know if it should change.
Note that exercising different sizes to fill the L1/L2/L3 caches is important for reliability of the results. (and the size as mentioned in the comment above)
benches/hash.rs
Outdated
.map(|[l, r]| [l.as_bytes().into(), r.as_bytes().into()]) | ||
.collect(); | ||
group.bench_with_input( | ||
BenchmarkId::new(format!("Blake3/256/{size}"), size), |
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 doing /{size}
is redundant here. We could probably just do: BenchmarkId::new("Blake3_256", size)
.
benches/hash.rs
Outdated
.collect(); | ||
|
||
group.bench_with_input( | ||
BenchmarkId::new(format!("RPO256/{size}"), size), |
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 doing /{size}
is redundant here. We could probably just do: BenchmarkId::new("RPO256", size)
.
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.
removed the size of all ids
cc4fd92
to
1d408ec
Compare
59e6822
to
9ddba07
Compare
9ddba07
to
7256709
Compare
Describe your changes
A few changes to the hash benchmarks done while reviewing #76
Ref: #76 (comment)
Checklist before requesting a review
next
according to naming convention.