Skip to content

Commit 6b004a4

Browse files
committed
Update Uint::div benchmarks
1 parent 10eec67 commit 6b004a4

File tree

1 file changed

+51
-4
lines changed

1 file changed

+51
-4
lines changed

benches/uint.rs

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,19 @@ fn bench_division(c: &mut Criterion) {
219219
let mut rng = make_rng();
220220
let mut group = c.benchmark_group("wrapping ops");
221221

222-
group.bench_function("div/rem, U256/U128, full size", |b| {
222+
group.bench_function("div/rem, U256/U128", |b| {
223+
b.iter_batched(
224+
|| {
225+
let x = U256::random(&mut rng);
226+
let y = U128::random(&mut rng);
227+
(x, NonZero::new(y).unwrap())
228+
},
229+
|(x, y)| black_box(x.div_rem(&y)),
230+
BatchSize::SmallInput,
231+
)
232+
});
233+
234+
group.bench_function("div/rem, U256/U128 (in U256)", |b| {
223235
b.iter_batched(
224236
|| {
225237
let x = U256::random(&mut rng);
@@ -232,6 +244,18 @@ fn bench_division(c: &mut Criterion) {
232244
)
233245
});
234246

247+
group.bench_function("div/rem, U256/U128 (in U512)", |b| {
248+
b.iter_batched(
249+
|| {
250+
let x = U256::random(&mut rng);
251+
let y: U512 = U128::random(&mut rng).resize();
252+
(x, NonZero::new(y).unwrap())
253+
},
254+
|(x, y)| black_box(x.div_rem(&y)),
255+
BatchSize::SmallInput,
256+
)
257+
});
258+
235259
group.bench_function("div/rem_vartime, U256/U128, full size", |b| {
236260
b.iter_batched(
237261
|| {
@@ -244,12 +268,35 @@ fn bench_division(c: &mut Criterion) {
244268
)
245269
});
246270

247-
group.bench_function("rem, U256/U128, full size", |b| {
271+
group.bench_function("rem, U256/U128", |b| {
248272
b.iter_batched(
249273
|| {
250274
let x = U256::random(&mut rng);
251-
let y_half = U128::random(&mut rng);
252-
let y: U256 = (y_half, U128::ZERO).into();
275+
let y = U128::random(&mut rng);
276+
(x, NonZero::new(y).unwrap())
277+
},
278+
|(x, y)| black_box(x.rem(&y)),
279+
BatchSize::SmallInput,
280+
)
281+
});
282+
283+
group.bench_function("rem, U256/U128 (in U256)", |b| {
284+
b.iter_batched(
285+
|| {
286+
let x = U256::random(&mut rng);
287+
let y: U256 = U128::random(&mut rng).resize();
288+
(x, NonZero::new(y).unwrap())
289+
},
290+
|(x, y)| black_box(x.rem(&y)),
291+
BatchSize::SmallInput,
292+
)
293+
});
294+
295+
group.bench_function("rem, U256/U128 (in U512)", |b| {
296+
b.iter_batched(
297+
|| {
298+
let x = U256::random(&mut rng);
299+
let y: U512 = U128::random(&mut rng).resize();
253300
(x, NonZero::new(y).unwrap())
254301
},
255302
|(x, y)| black_box(x.rem(&y)),

0 commit comments

Comments
 (0)