Skip to content
Open
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
6 changes: 5 additions & 1 deletion .github/workflows/benchmarks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,9 @@ jobs:
mode: instrumentation
run: |
echo "Running benchmarks for ${{ matrix.benchmark-target.package }}"
cargo codspeed run -p ${{ matrix.benchmark-target.package }} > /dev/null
if [[ "${{ matrix.benchmark-target.package }}" == "uu_factor" ]]; then
cargo codspeed run -p ${{ matrix.benchmark-target.package }}
else
cargo codspeed run -p ${{ matrix.benchmark-target.package }} > /dev/null
fi
token: ${{ secrets.CODSPEED_TOKEN }}
2 changes: 2 additions & 0 deletions .vscode/cspell.dictionaries/jargon.wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ wordlists
xattrs
xpass

jemalloc
jemallocator
# * abbreviations
AMPM
ampm
Expand Down
39 changes: 39 additions & 0 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,8 @@ icu_locale = "2.0.0"
icu_provider = "2.0.0"
indicatif = "0.18.0"
itertools = "0.14.0"
jemalloc-ctl = "0.5"
jemallocator = "0.5"
jiff = { version = "0.2.10", default-features = false, features = [
"std",
"alloc",
Expand All @@ -347,6 +349,7 @@ nix = { version = "0.30", default-features = false }
nom = "8.0.0"
notify = { version = "=8.2.0", features = ["macos_kqueue"] }
num-bigint = "0.4.4"
num-integer = "0.1"
num-prime = "0.4.4"
num-traits = "0.2.19"
onig = { version = "~6.5.1", default-features = false }
Expand Down
4 changes: 4 additions & 0 deletions src/uu/factor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ divan = { workspace = true }
rand = { workspace = true }
uucore = { workspace = true, features = ["benchmark"] }

[target.'cfg(any(target_os = "linux", target_os = "macos", target_os = "freebsd"))'.dev-dependencies]
jemalloc-ctl = { workspace = true }
jemallocator = { workspace = true }

[lib]
path = "src/factor.rs"

Expand Down
26 changes: 26 additions & 0 deletions src/uu/factor/benches/factor_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,42 @@ use divan::{Bencher, black_box};
use uu_factor::uumain;
use uucore::benchmark::run_util_function;

#[cfg(any(target_os = "linux", target_os = "macos", target_os = "freebsd"))]
use jemallocator::Jemalloc;

#[cfg(any(target_os = "linux", target_os = "macos", target_os = "freebsd"))]
#[global_allocator]
static ALLOC: Jemalloc = Jemalloc;

#[cfg(any(target_os = "linux", target_os = "macos", target_os = "freebsd"))]
fn log_jemalloc_stats(label: &str) {
use jemalloc_ctl::{epoch, stats};

epoch::advance().unwrap();
let allocated = stats::allocated::read().unwrap();
let resident = stats::resident::read().unwrap();

println!(
"jemalloc {label}: allocated={} bytes, resident={} bytes",
allocated, resident
);
}

#[cfg(not(any(target_os = "linux", target_os = "macos", target_os = "freebsd")))]
fn log_jemalloc_stats(_label: &str) {}

/// Benchmark multiple u64 digits
#[divan::bench(args = [(2)])]
fn factor_multiple_u64s(bencher: Bencher, start_num: u64) {
bencher
// this is a range of 5000 different u128 integers
.with_inputs(|| (start_num, start_num + 2500))
.bench_values(|(start_u64, end_u64)| {
log_jemalloc_stats("before factor_multiple_u64s");
for u64_digit in start_u64..=end_u64 {
black_box(run_util_function(uumain, &[&u64_digit.to_string()]));
}
log_jemalloc_stats("after factor_multiple_u64s");
});
}

Expand Down
Loading
Loading