Skip to content

Commit baa2e83

Browse files
committed
Add shift benchmarks for BoxedUint
1 parent 4d12e8d commit baa2e83

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ name = "boxed_residue"
5656
harness = false
5757
required-features = ["alloc"]
5858

59+
[[bench]]
60+
name = "boxed_uint"
61+
harness = false
62+
required-features = ["alloc"]
63+
5964
[[bench]]
6065
name = "dyn_residue"
6166
harness = false

benches/boxed_uint.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
use criterion::{black_box, criterion_group, criterion_main, BatchSize, Criterion};
2+
use crypto_bigint::BoxedUint;
3+
use num_bigint::BigUint;
4+
use rand_core::OsRng;
5+
6+
/// Size of `BoxedUint` to use in benchmark.
7+
const UINT_BITS: u32 = 4096;
8+
9+
fn bench_shifts(c: &mut Criterion) {
10+
let mut group = c.benchmark_group("bit shifts");
11+
12+
group.bench_function("shl_vartime", |b| {
13+
b.iter_batched(
14+
|| BoxedUint::random(&mut OsRng, UINT_BITS),
15+
|x| black_box(x.shl_vartime(UINT_BITS / 2 + 10)),
16+
BatchSize::SmallInput,
17+
)
18+
});
19+
20+
group.bench_function("shl", |b| {
21+
b.iter_batched(
22+
|| BoxedUint::random(&mut OsRng, UINT_BITS),
23+
|x| x.shl(UINT_BITS / 2 + 10),
24+
BatchSize::SmallInput,
25+
)
26+
});
27+
28+
group.bench_function("shr_vartime", |b| {
29+
b.iter_batched(
30+
|| BoxedUint::random(&mut OsRng, UINT_BITS),
31+
|x| black_box(x.shr_vartime(UINT_BITS / 2 + 10)),
32+
BatchSize::SmallInput,
33+
)
34+
});
35+
36+
group.bench_function("shr", |b| {
37+
b.iter_batched(
38+
|| BoxedUint::random(&mut OsRng, UINT_BITS),
39+
|x| x.shr(UINT_BITS / 2 + 10),
40+
BatchSize::SmallInput,
41+
)
42+
});
43+
44+
group.finish();
45+
}
46+
47+
criterion_group!(benches, bench_shifts);
48+
49+
criterion_main!(benches);

0 commit comments

Comments
 (0)