Skip to content

Commit 2f2997c

Browse files
author
Andronik Ordian
committed
uint: compare mul by u32 and u64
1 parent acbcfe7 commit 2f2997c

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

uint/benches/bigint.rs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ criterion_group!(
6262
u512_mul,
6363
u512_div,
6464
u512_rem,
65+
u512_mul_u32_vs_u64,
6566
mulmod_u512_vs_biguint_vs_gmp,
6667
conversions,
6768
u512_bit_and,
@@ -141,7 +142,14 @@ fn u256_mul(c: &mut Criterion) {
141142
black_box(x.overflowing_mul(y).0)
142143
})
143144
},
144-
vec![(U256::max_value(), 1u64), (U256::from(3), u64::max_value())],
145+
vec![
146+
(U256::max_value(), 1u64),
147+
(U256::from(3), u64::max_value()),
148+
(
149+
U256::from_dec_str("21674844646682989462120101885968193938394323990565507610662749").unwrap(),
150+
173,
151+
),
152+
],
145153
),
146154
);
147155
}
@@ -330,6 +338,31 @@ fn bench_convert_to_gmp(b: &mut Bencher, i: u64) {
330338
});
331339
}
332340

341+
fn u512_mul_u32_vs_u64(c: &mut Criterion) {
342+
let mods = vec![1u32, 42, 10_000_001, u32::max_value()];
343+
c.bench(
344+
"multiply u512 by u32 vs u64",
345+
ParameterizedBenchmark::new("u32", |b, i| bench_u512_mul_u32(b, *i), mods)
346+
.with_function("u64", |b, i| bench_u512_mul_u64(b, u64::from(*i))),
347+
);
348+
}
349+
350+
fn bench_u512_mul_u32(b: &mut Bencher, i: u32) {
351+
let x =
352+
U512::from_str("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF").unwrap();
353+
b.iter(|| {
354+
black_box(x * i)
355+
});
356+
}
357+
358+
fn bench_u512_mul_u64(b: &mut Bencher, i: u64) {
359+
let x =
360+
U512::from_str("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF").unwrap();
361+
b.iter(|| {
362+
black_box(x * i)
363+
});
364+
}
365+
333366
fn mulmod_u512_vs_biguint_vs_gmp(c: &mut Criterion) {
334367
let mods = vec![1u64, 42, 10_000_001, u64::max_value()];
335368
c.bench(

0 commit comments

Comments
 (0)