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

factor: add -h/--exponents option (#4710)

* factor: add -h/--exponents option

* Factor: Rebase, add -h/--exponents options
This commit is contained in:
Ideflop 2023-04-14 21:20:19 +02:00 committed by GitHub
parent a04fc0508e
commit 6a54d820ac
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 121 additions and 29 deletions

View file

@ -7,6 +7,8 @@ description = "Benchmarks for the uu_factor integer factorization tool"
homepage = "https://github.com/uutils/coreutils"
edition = "2021"
[workspace]
[dependencies]
uu_factor = { path = "../../../src/uu/factor" }
@ -14,7 +16,7 @@ uu_factor = { path = "../../../src/uu/factor" }
array-init = "2.0.0"
criterion = "0.3"
rand = "0.8"
rand_chacha = "0.2.2"
rand_chacha = "0.3.1"
[[bench]]
name = "gcd"

View file

@ -6,7 +6,7 @@ fn gcd(c: &mut Criterion) {
// Deterministic RNG; use an explicitly-named RNG to guarantee stability
use rand::{RngCore, SeedableRng};
use rand_chacha::ChaCha8Rng;
const SEED: u64 = 0xa_b4d_1dea_dead_cafe;
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()))
@ -22,7 +22,7 @@ fn gcd(c: &mut Criterion) {
},
);
}
group.finish()
group.finish();
}
criterion_group!(benches, gcd);

View file

@ -7,12 +7,7 @@ fn table(c: &mut Criterion) {
check_personality();
const INPUT_SIZE: usize = 128;
assert!(
INPUT_SIZE % CHUNK_SIZE == 0,
"INPUT_SIZE ({}) is not divisible by CHUNK_SIZE ({})",
INPUT_SIZE,
CHUNK_SIZE
);
let inputs = {
// Deterministic RNG; use an explicitly-named RNG to guarantee stability
use rand::{RngCore, SeedableRng};
@ -29,42 +24,40 @@ fn table(c: &mut Criterion) {
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.clone();
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())
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.clone();
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)
factor(n, f);
}
})
});
});
}
group.finish()
group.finish();
}
#[cfg(target_os = "linux")]
fn check_personality() {
use std::fs;
const ADDR_NO_RANDOMIZE: u64 = 0x0040000;
const PERSONALITY_PATH: &'static str = "/proc/self/personality";
const PERSONALITY_PATH: &str = "/proc/self/personality";
let p_string = fs::read_to_string(PERSONALITY_PATH)
.expect(&format!("Couldn't read '{}'", PERSONALITY_PATH))
.strip_suffix("\n")
.unwrap_or_else(|_| panic!("Couldn't read '{}'", PERSONALITY_PATH))
.strip_suffix('\n')
.unwrap()
.to_owned();
let personality = u64::from_str_radix(&p_string, 16).expect(&format!(
"Expected a hex value for personality, got '{:?}'",
p_string
));
let personality = u64::from_str_radix(&p_string, 16)
.unwrap_or_else(|_| panic!("Expected a hex value for personality, got '{:?}'", p_string));
if personality & ADDR_NO_RANDOMIZE == 0 {
eprintln!(
"WARNING: Benchmarking with ASLR enabled (personality is {:x}), results might not be reproducible.",