mirror of
https://github.com/uutils/coreutils
synced 2024-12-13 06:42:42 +00:00
factor: Add annotations for coz, the causal profiler (#2142)
* factor: Add annotations for coz, the causal profiler * Update Cargo.lock Generated with `nix-shell -p rustup --run 'cargo +1.40.0 update'`
This commit is contained in:
parent
1ca6edb560
commit
b89978a4c9
4 changed files with 32 additions and 8 deletions
21
Cargo.lock
generated
21
Cargo.lock
generated
|
@ -333,6 +333,16 @@ dependencies = [
|
||||||
"walkdir",
|
"walkdir",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "coz"
|
||||||
|
version = "0.1.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "cef55b3fe2f5477d59e12bc792e8b3c95a25bd099eadcfae006ecea136de76e2"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
"once_cell",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cpp"
|
name = "cpp"
|
||||||
version = "0.5.6"
|
version = "0.5.6"
|
||||||
|
@ -608,7 +618,7 @@ checksum = "1d34cfa13a63ae058bfa601fe9e313bbdb3746427c1459185464ce0fcf62e1e8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if 1.0.0",
|
"cfg-if 1.0.0",
|
||||||
"libc",
|
"libc",
|
||||||
"redox_syscall 0.2.6",
|
"redox_syscall 0.2.7",
|
||||||
"winapi 0.3.9",
|
"winapi 0.3.9",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -1249,9 +1259,9 @@ checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "redox_syscall"
|
name = "redox_syscall"
|
||||||
version = "0.2.6"
|
version = "0.2.7"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8270314b5ccceb518e7e578952f0b72b88222d02e8f77f5ecf7abbb673539041"
|
checksum = "85dd92e586f7355c633911e11f77f3d12f04b1b1bd76a198bd34ae3af8341ef2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags",
|
"bitflags",
|
||||||
]
|
]
|
||||||
|
@ -1262,7 +1272,7 @@ version = "0.1.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8440d8acb4fd3d277125b4bd01a6f38aee8d814b3b5fc09b3f2b825d37d3fe8f"
|
checksum = "8440d8acb4fd3d277125b4bd01a6f38aee8d814b3b5fc09b3f2b825d37d3fe8f"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"redox_syscall 0.2.6",
|
"redox_syscall 0.2.7",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -1533,7 +1543,7 @@ checksum = "077185e2eac69c3f8379a4298e1e07cd36beb962290d4a51199acf0fdc10607e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
"numtoa",
|
"numtoa",
|
||||||
"redox_syscall 0.2.6",
|
"redox_syscall 0.2.7",
|
||||||
"redox_termios",
|
"redox_termios",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -1898,6 +1908,7 @@ dependencies = [
|
||||||
name = "uu_factor"
|
name = "uu_factor"
|
||||||
version = "0.0.6"
|
version = "0.0.6"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"coz",
|
||||||
"criterion",
|
"criterion",
|
||||||
"num-traits",
|
"num-traits",
|
||||||
"paste",
|
"paste",
|
||||||
|
|
|
@ -14,8 +14,8 @@ edition = "2018"
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
num-traits = "0.2.13" # used in src/numerics.rs, which is included by build.rs
|
num-traits = "0.2.13" # used in src/numerics.rs, which is included by build.rs
|
||||||
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
coz = { version = "0.1.3", optional = true }
|
||||||
num-traits = "0.2.13" # Needs at least version 0.2.13 for "OverflowingAdd"
|
num-traits = "0.2.13" # Needs at least version 0.2.13 for "OverflowingAdd"
|
||||||
rand = { version="0.7", features=["small_rng"] }
|
rand = { version="0.7", features=["small_rng"] }
|
||||||
smallvec = { version="0.6.14, < 1.0" }
|
smallvec = { version="0.6.14, < 1.0" }
|
||||||
|
|
|
@ -125,6 +125,8 @@ fn _factor<A: Arithmetic + miller_rabin::Basis>(num: u64, f: Factors) -> Factors
|
||||||
let n = A::new(num);
|
let n = A::new(num);
|
||||||
let divisor = match miller_rabin::test::<A>(n) {
|
let divisor = match miller_rabin::test::<A>(n) {
|
||||||
Prime => {
|
Prime => {
|
||||||
|
#[cfg(feature="coz")]
|
||||||
|
coz::progress!("factor found");
|
||||||
let mut r = f;
|
let mut r = f;
|
||||||
r.push(num);
|
r.push(num);
|
||||||
return r;
|
return r;
|
||||||
|
@ -139,6 +141,8 @@ fn _factor<A: Arithmetic + miller_rabin::Basis>(num: u64, f: Factors) -> Factors
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn factor(mut n: u64) -> Factors {
|
pub fn factor(mut n: u64) -> Factors {
|
||||||
|
#[cfg(feature="coz")]
|
||||||
|
coz::begin!("factorization");
|
||||||
let mut factors = Factors::one();
|
let mut factors = Factors::one();
|
||||||
|
|
||||||
if n < 2 {
|
if n < 2 {
|
||||||
|
@ -152,16 +156,23 @@ pub fn factor(mut n: u64) -> Factors {
|
||||||
}
|
}
|
||||||
|
|
||||||
if n == 1 {
|
if n == 1 {
|
||||||
|
#[cfg(feature="coz")]
|
||||||
|
coz::end!("factorization");
|
||||||
return factors;
|
return factors;
|
||||||
}
|
}
|
||||||
|
|
||||||
let (factors, n) = table::factor(n, factors);
|
let (factors, n) = table::factor(n, factors);
|
||||||
|
|
||||||
if n < (1 << 32) {
|
let r = if n < (1 << 32) {
|
||||||
_factor::<Montgomery<u32>>(n, factors)
|
_factor::<Montgomery<u32>>(n, factors)
|
||||||
} else {
|
} else {
|
||||||
_factor::<Montgomery<u64>>(n, factors)
|
_factor::<Montgomery<u64>>(n, factors)
|
||||||
}
|
};
|
||||||
|
|
||||||
|
#[cfg(feature="coz")]
|
||||||
|
coz::end!("factorization");
|
||||||
|
|
||||||
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
|
@ -33,6 +33,8 @@ pub(crate) fn factor(mut num: u64, mut factors: Factors) -> (Factors, u64) {
|
||||||
if x <= ceil {
|
if x <= ceil {
|
||||||
num = x;
|
num = x;
|
||||||
k += 1;
|
k += 1;
|
||||||
|
#[cfg(feature="coz")]
|
||||||
|
coz::progress!("factor found");
|
||||||
} else {
|
} else {
|
||||||
if k > 0 {
|
if k > 0 {
|
||||||
factors.add(prime, k);
|
factors.add(prime, k);
|
||||||
|
|
Loading…
Reference in a new issue