Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 1 addition & 17 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,6 @@ members = [
"src/uu/stdbuf/src/libstdbuf",
"src/uucore",
"src/uucore_procs",
"tests/benches/factor",
"tests/uutests",
# "fuzz", # TODO
]
Expand Down
1 change: 1 addition & 0 deletions src/uu/factor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ path = "src/main.rs"

[dev-dependencies]
divan = { workspace = true }
rand = { workspace = true }
uucore = { workspace = true, features = ["benchmark"] }

[lib]
Expand Down
56 changes: 56 additions & 0 deletions src/uu/factor/benches/factor_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.

// spell-checker:ignore funcs

use divan::{Bencher, black_box};
use uu_factor::uumain;
use uucore::benchmark::run_util_function;
Expand Down Expand Up @@ -55,6 +57,60 @@ fn factor_multiple_big_uint(bencher: Bencher) {
}
*/

#[divan::bench()]
fn factor_table(bencher: Bencher) {
#[cfg(target_os = "linux")]
check_personality();

const INPUT_SIZE: usize = 128;

let inputs = {
// Deterministic RNG; use an explicitly-named RNG to guarantee stability
use rand::{RngCore, SeedableRng};
const SEED: u64 = 0xdead_bebe_ea75_cafe; // spell-checker:disable-line
let mut rng = rand::rngs::StdRng::seed_from_u64(SEED);

std::iter::repeat_with(move || {
let mut array = [0u64; INPUT_SIZE];
for item in &mut array {
*item = rng.next_u64();
}
array
})
.take(10)
.collect::<Vec<_>>()
};

bencher.bench(|| {
for a in &inputs {
for n in a {
divan::black_box(num_prime::nt_funcs::factors(*n, None));
}
}
});
}

#[cfg(target_os = "linux")]
fn check_personality() {
use std::fs;
const ADDR_NO_RANDOMIZE: u64 = 0x0040000;
const PERSONALITY_PATH: &str = "/proc/self/personality";

let p_string = fs::read_to_string(PERSONALITY_PATH)
.unwrap_or_else(|_| panic!("Couldn't read '{PERSONALITY_PATH}'"))
.strip_suffix('\n')
.unwrap()
.to_owned();

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 {personality:x}), results might not be reproducible."
);
}
}

fn main() {
divan::main();
}
20 changes: 0 additions & 20 deletions tests/benches/factor/Cargo.toml

This file was deleted.

62 changes: 0 additions & 62 deletions tests/benches/factor/benches/table.rs

This file was deleted.

Loading