Skip to content

Commit bc8bc51

Browse files
committed
Remove jemalloc dependencies from factor utility
The jemalloc allocator and related dependencies (jemalloc-ctl, jemalloc-sys, paste) were removed from the factor utility's benchmark code. This change simplifies the dependency tree and removes platform-specific allocator logic that was only used for memory profiling in benchmarks. The benchmark functionality remains intact, just without jemalloc-specific memory statistics collection. Additionally, a new regression test was added to verify correct factorization of a very large number (15111234931751377131713914373267893176342349831) to ensure the utility handles large inputs properly.
1 parent 0e20f3c commit bc8bc51

File tree

4 files changed

+12
-66
lines changed

4 files changed

+12
-66
lines changed

Cargo.lock

Lines changed: 0 additions & 39 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: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,6 @@ path = "src/main.rs"
3333
divan = { workspace = true }
3434
uucore = { workspace = true, features = ["benchmark"] }
3535

36-
[target.'cfg(any(target_os = "linux", target_os = "macos", target_os = "freebsd"))'.dev-dependencies]
37-
jemalloc-ctl = { workspace = true }
38-
jemallocator = { workspace = true }
39-
4036
[lib]
4137
path = "src/factor.rs"
4238

src/uu/factor/benches/factor_bench.rs

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,39 +9,16 @@ use divan::{Bencher, black_box};
99
use uu_factor::uumain;
1010
use uucore::benchmark::run_util_function;
1111

12-
#[cfg(any(target_os = "linux", target_os = "macos", target_os = "freebsd"))]
13-
use jemallocator::Jemalloc;
14-
15-
#[cfg(any(target_os = "linux", target_os = "macos", target_os = "freebsd"))]
16-
#[global_allocator]
17-
static ALLOC: Jemalloc = Jemalloc;
18-
19-
#[cfg(any(target_os = "linux", target_os = "macos", target_os = "freebsd"))]
20-
fn log_jemalloc_stats(label: &str) {
21-
use jemalloc_ctl::{epoch, stats};
22-
23-
epoch::advance().unwrap();
24-
let allocated = stats::allocated::read().unwrap();
25-
let resident = stats::resident::read().unwrap();
26-
27-
println!("jemalloc {label}: allocated={allocated} bytes, resident={resident} bytes");
28-
}
29-
30-
#[cfg(not(any(target_os = "linux", target_os = "macos", target_os = "freebsd")))]
31-
fn log_jemalloc_stats(_label: &str) {}
32-
3312
/// Benchmark multiple u64 digits
3413
#[divan::bench(args = [(2)])]
3514
fn factor_multiple_u64s(bencher: Bencher, start_num: u64) {
3615
bencher
3716
// this is a range of 5000 different u128 integers
3817
.with_inputs(|| (start_num, start_num + 2500))
3918
.bench_values(|(start_u64, end_u64)| {
40-
log_jemalloc_stats("before factor_multiple_u64s");
4119
for u64_digit in start_u64..=end_u64 {
4220
black_box(run_util_function(uumain, &[&u64_digit.to_string()]));
4321
}
44-
log_jemalloc_stats("after factor_multiple_u64s");
4522
});
4623
}
4724

tests/by-util/test_factor.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,18 @@ fn test_cli_args() {
169169
.stdout_contains("9: 3 3");
170170
}
171171

172+
#[test]
173+
fn test_large_regression_number() {
174+
let n = "15111234931751377131713914373267893176342349831";
175+
new_ucmd!()
176+
.arg(n)
177+
.timeout(Duration::from_secs(240))
178+
.succeeds()
179+
.stdout_is(format!(
180+
"{n}: 29 127 115319 1971799 82465494029827 218807630881735711\n"
181+
));
182+
}
183+
172184
#[test]
173185
fn test_random() {
174186
let log_num_primes = f64::from(u32::try_from(NUM_PRIMES).unwrap()).log2().ceil();

0 commit comments

Comments
 (0)