Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d977e29

Browse files
committed
factor/bench: reduced range on u64 and u128 benchmarking and remove single u64/u128/big_uint benchmark tests
1 parent 9e788c7 commit d977e29

File tree

1 file changed

+10
-35
lines changed

1 file changed

+10
-35
lines changed

src/uu/factor/benches/factor_bench.rs

Lines changed: 10 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,42 +7,26 @@ use divan::{Bencher, black_box};
77
use uu_factor::uumain;
88
use uucore::benchmark::run_util_function;
99

10-
/// Benchmark one u64 digit
11-
#[divan::bench(args = [1000000])]
12-
fn factor_single_u64(bencher: Bencher, num: u64) {
13-
bencher.with_inputs(|| num).bench_values(|single_u64| {
14-
black_box(run_util_function(uumain, &[&single_u64.to_string()]));
15-
});
16-
}
17-
1810
/// Benchmark multiple u64 digits
19-
#[divan::bench(args = [(2, 50001)])]
20-
fn factor_multiple_u64s(bencher: Bencher, (start_num, end_num): (u64, u64)) {
11+
#[divan::bench(args = [(2)])]
12+
fn factor_multiple_u64s(bencher: Bencher, start_num: u64) {
2113
bencher
22-
// this is a range of 50000 million different u128 integers
23-
.with_inputs(|| (start_num, end_num))
14+
// this is a range of 5000 different u128 integers
15+
.with_inputs(|| (start_num, start_num + 2500))
2416
.bench_values(|(start_u64, end_u64)| {
2517
for u64_digit in start_u64..=end_u64 {
2618
black_box(run_util_function(uumain, &[&u64_digit.to_string()]));
2719
}
2820
});
2921
}
3022

31-
/// Benchmark one u128 digit
32-
#[divan::bench(args = [18446744073709551616])]
33-
fn factor_single_u128(bencher: Bencher, num: u128) {
34-
bencher.with_inputs(|| num).bench_values(|single_u128| {
35-
black_box(run_util_function(uumain, &[&single_u128.to_string()]));
36-
});
37-
}
38-
3923
/// Benchmark multiple u128 digits
40-
#[divan::bench(args = [(18446744073709551616, 18446744073709601616)])]
41-
fn factor_multiple_u128s(bencher: Bencher, (start_num, end_num): (u128, u128)) {
24+
#[divan::bench(args = [(18446744073709551616)])]
25+
fn factor_multiple_u128s(bencher: Bencher, start_num: u128) {
4226
bencher
4327
.with_inputs(|| {
44-
// this is a range of 50000 million different u128 integers
45-
(start_num, end_num)
28+
// this is a range of 1000 different u128 integers
29+
(start_num, start_num + 1000)
4630
})
4731
.bench_values(|(start_u128, end_u128)| {
4832
for u128_digit in start_u128..=end_u128 {
@@ -51,22 +35,13 @@ fn factor_multiple_u128s(bencher: Bencher, (start_num, end_num): (u128, u128)) {
5135
});
5236
}
5337

54-
/// Benchmark single > u128::MAX digits
55-
#[divan::bench]
56-
fn factor_single_big_uint(bencher: Bencher) {
57-
// max u128 value is 340_282_366_920_938_463_463_374_607_431_768_211_455
58-
bencher
59-
.with_inputs(|| "340_282_366_920_938_463_463_374_607_431_768_211_456")
60-
.bench_values(|single_big_uint| {
61-
black_box(run_util_function(uumain, &[single_big_uint]));
62-
});
63-
}
64-
6538
/// Benchmark multiple > u128::MAX digits
6639
#[divan::bench]
6740
fn factor_multiple_big_uint(bencher: Bencher) {
6841
// max u128 value is 340_282_366_920_938_463_463_374_607_431_768_211_455
6942
bencher
43+
// this is a range of 3 different BigUints. The range is small due to
44+
// some BigUints being unable to be factorized into prime numbers properly
7045
.with_inputs(|| (768_211_459_u64, 768_211_461_u64))
7146
.bench_values(|(start_big_uint, end_big_uint)| {
7247
for digit in start_big_uint..=end_big_uint {

0 commit comments

Comments
 (0)