bench-criterion base program
This commit is contained in:
parent
59f89cef80
commit
0fd04c359c
|
@ -3,34 +3,9 @@
|
||||||
version = 3
|
version = 3
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "c-bindings"
|
name = "bench-criterion"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
|
||||||
"cc",
|
|
||||||
"cty",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "cc"
|
|
||||||
version = "1.0.83"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0"
|
|
||||||
dependencies = [
|
|
||||||
"libc",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "cty"
|
|
||||||
version = "0.2.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "b365fabc795046672053e29c954733ec3b05e4be654ab130fe8f1f94d7051f35"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "libc"
|
|
||||||
version = "0.2.147"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rs-basic"
|
name = "rs-basic"
|
||||||
version = "0.1.0"
|
version = "0.2.0"
|
||||||
|
|
|
@ -2,14 +2,16 @@
|
||||||
publish = false
|
publish = false
|
||||||
members = [
|
members = [
|
||||||
".",
|
".",
|
||||||
|
"members/bench-criterion",
|
||||||
]
|
]
|
||||||
default-members = [
|
default-members = [
|
||||||
".",
|
".",
|
||||||
|
"members/bench-criterion",
|
||||||
]
|
]
|
||||||
|
|
||||||
[package]
|
[package]
|
||||||
name = "rs-basic"
|
name = "rs-basic"
|
||||||
version = "0.1.0"
|
version = "0.2.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
authors = ["Christoph J. Scherr <softwar@cscherr.de>"]
|
authors = ["Christoph J. Scherr <softwar@cscherr.de>"]
|
||||||
publish = false
|
publish = false
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
[package]
|
||||||
|
name = "bench-criterion"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
|
@ -0,0 +1,26 @@
|
||||||
|
fn main() {
|
||||||
|
let n: f32 = std::env::args().collect::<Vec<String>>()[1]
|
||||||
|
.parse::<f32>()
|
||||||
|
.expect("bad input number");
|
||||||
|
println!("rsqrt:\t\t{}", inverse_sqrt(n));
|
||||||
|
println!("f_rsqrt:\t{}", fast_inverse_sqrt(n));
|
||||||
|
}
|
||||||
|
|
||||||
|
fn inverse_sqrt(n: f32) -> f32 {
|
||||||
|
1f32 / n.sqrt()
|
||||||
|
}
|
||||||
|
|
||||||
|
union MixedIntFloat {
|
||||||
|
f: f32,
|
||||||
|
i: u32,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// see https://en.wikipedia.org/wiki/Fast_inverse_square_root
|
||||||
|
fn fast_inverse_sqrt(n: f32) -> f32 {
|
||||||
|
let mut conv: MixedIntFloat = MixedIntFloat { f: n };
|
||||||
|
unsafe {
|
||||||
|
conv.i = 0x5f3759df - (conv.i >> 1);
|
||||||
|
conv.f *= 1.5f32 - (n* 0.5f32 * conv.f * conv.f);
|
||||||
|
conv.f
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue