1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

use num_prime for factorisation to fix gnu test

This commit is contained in:
Ulrich Hornung 2024-04-20 23:29:26 +02:00
parent 64027e5a57
commit d202baba97
22 changed files with 298 additions and 1690 deletions

View file

@ -17,10 +17,10 @@ array-init = "2.0.0"
criterion = "0.3"
rand = "0.8"
rand_chacha = "0.3.1"
num-bigint = "0.4.4"
num-prime = "0.4.3"
num-traits = "0.2.18"
[[bench]]
name = "gcd"
harness = false
[[bench]]
name = "table"

View file

@ -1,33 +0,0 @@
// This file is part of the uutils coreutils package.
//
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
use uu_factor::numeric;
fn gcd(c: &mut Criterion) {
let inputs = {
// Deterministic RNG; use an explicitly-named RNG to guarantee stability
use rand::{RngCore, SeedableRng};
use rand_chacha::ChaCha8Rng;
const SEED: u64 = 0xab4d_1dea_dead_cafe;
let mut rng = ChaCha8Rng::seed_from_u64(SEED);
std::iter::repeat_with(move || (rng.next_u64(), rng.next_u64()))
};
let mut group = c.benchmark_group("gcd");
for (n, m) in inputs.take(10) {
group.bench_with_input(
BenchmarkId::from_parameter(format!("{}_{}", n, m)),
&(n, m),
|b, &(n, m)| {
b.iter(|| numeric::gcd(n, m));
},
);
}
group.finish();
}
criterion_group!(benches, gcd);
criterion_main!(benches);

View file

@ -2,9 +2,11 @@
//
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
// spell-checker:ignore funcs
use array_init::array_init;
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput};
use uu_factor::{table::*, Factors};
fn table(c: &mut Criterion) {
#[cfg(target_os = "linux")]
@ -26,21 +28,10 @@ fn table(c: &mut Criterion) {
group.throughput(Throughput::Elements(INPUT_SIZE as _));
for a in inputs.take(10) {
let a_str = format!("{:?}", a);
group.bench_with_input(BenchmarkId::new("factor_chunk", &a_str), &a, |b, &a| {
b.iter(|| {
let mut n_s = a;
let mut f_s: [_; INPUT_SIZE] = array_init(|_| Factors::one());
for (n_s, f_s) in n_s.chunks_mut(CHUNK_SIZE).zip(f_s.chunks_mut(CHUNK_SIZE)) {
factor_chunk(n_s.try_into().unwrap(), f_s.try_into().unwrap());
}
});
});
group.bench_with_input(BenchmarkId::new("factor", &a_str), &a, |b, &a| {
b.iter(|| {
let mut n_s = a;
let mut f_s: [_; INPUT_SIZE] = array_init(|_| Factors::one());
for (n, f) in n_s.iter_mut().zip(f_s.iter_mut()) {
factor(n, f);
for n in a {
let _r = num_prime::nt_funcs::factors(n, None);
}
});
});