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

Skip to content

Commit c615a0f

Browse files
authored
Merge pull request #9182 from asder8215/factor_benchmarking
Factor: base benchmarking for single/multiple u64, u128, and >u128
1 parent 1074071 commit c615a0f

File tree

4 files changed

+66
-0
lines changed

4 files changed

+66
-0
lines changed

.github/workflows/benchmarks.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ jobs:
4343
- { package: uu_unexpand }
4444
- { package: uu_uniq }
4545
- { package: uu_wc }
46+
- { package: uu_factor }
4647
steps:
4748
- uses: actions/checkout@v5
4849
with:

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/uu/factor/Cargo.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,13 @@ fluent = { workspace = true }
2929
name = "factor"
3030
path = "src/main.rs"
3131

32+
[dev-dependencies]
33+
divan = { workspace = true }
34+
uucore = { workspace = true, features = ["benchmark"] }
35+
3236
[lib]
3337
path = "src/factor.rs"
38+
39+
[[bench]]
40+
name = "factor_bench"
41+
harness = false
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// This file is part of the uutils coreutils package.
2+
//
3+
// For the full copyright and license information, please view the LICENSE
4+
// file that was distributed with this source code.
5+
6+
use divan::{Bencher, black_box};
7+
use uu_factor::uumain;
8+
use uucore::benchmark::run_util_function;
9+
10+
/// Benchmark multiple u64 digits
11+
#[divan::bench(args = [(2)])]
12+
fn factor_multiple_u64s(bencher: Bencher, start_num: u64) {
13+
bencher
14+
// this is a range of 5000 different u128 integers
15+
.with_inputs(|| (start_num, start_num + 2500))
16+
.bench_values(|(start_u64, end_u64)| {
17+
for u64_digit in start_u64..=end_u64 {
18+
black_box(run_util_function(uumain, &[&u64_digit.to_string()]));
19+
}
20+
});
21+
}
22+
23+
/// Benchmark multiple u128 digits
24+
#[divan::bench(args = [(18446744073709551616)])]
25+
fn factor_multiple_u128s(bencher: Bencher, start_num: u128) {
26+
bencher
27+
.with_inputs(|| {
28+
// this is a range of 1000 different u128 integers
29+
(start_num, start_num + 1000)
30+
})
31+
.bench_values(|(start_u128, end_u128)| {
32+
for u128_digit in start_u128..=end_u128 {
33+
black_box(run_util_function(uumain, &[&u128_digit.to_string()]));
34+
}
35+
});
36+
}
37+
38+
/// Benchmark multiple > u128::MAX digits
39+
#[divan::bench]
40+
fn factor_multiple_big_uint(bencher: Bencher) {
41+
// max u128 value is 340_282_366_920_938_463_463_374_607_431_768_211_455
42+
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
45+
.with_inputs(|| (768_211_459_u64, 768_211_461_u64))
46+
.bench_values(|(start_big_uint, end_big_uint)| {
47+
for digit in start_big_uint..=end_big_uint {
48+
let big_uint_str = format!("340282366920938463463374607431768211456{digit}");
49+
black_box(run_util_function(uumain, &[&big_uint_str]));
50+
}
51+
});
52+
}
53+
54+
fn main() {
55+
divan::main();
56+
}

0 commit comments

Comments
 (0)