mirror of https://github.com/dnomd343/klotski.git
Dnomd343
2 years ago
7 changed files with 134 additions and 12 deletions
@ -0,0 +1,58 @@ |
|||
#[derive(Debug)] |
|||
pub(crate) struct Duration { |
|||
picos: u64 |
|||
} |
|||
|
|||
impl Duration { |
|||
#[allow(dead_code)] |
|||
pub(crate) fn from_ns(ns: f64) -> Duration { |
|||
Duration { |
|||
picos: (ns * (1_000 as f64)) as u64 |
|||
} |
|||
} |
|||
|
|||
#[allow(dead_code)] |
|||
pub(crate) fn from_us(us: f64) -> Duration { |
|||
Duration { |
|||
picos: (us * (1_000_000 as f64)) as u64 |
|||
} |
|||
} |
|||
|
|||
#[allow(dead_code)] |
|||
pub(crate) fn from_ms(ms: f64) -> Duration { |
|||
Duration { |
|||
picos: (ms * (1_000_000_000 as f64)) as u64 |
|||
} |
|||
} |
|||
|
|||
#[allow(dead_code)] |
|||
pub(crate) fn from_s(s: f64) -> Duration { |
|||
Duration { |
|||
picos: (s * (1_000_000_000_000 as i64 as f64)) as u64 |
|||
} |
|||
} |
|||
|
|||
#[allow(dead_code)] |
|||
pub(crate) fn to_ns(&self) -> String { |
|||
let tmp = self.picos as f64 / (1_000 as f64); |
|||
format!("{:.03}ns", tmp) |
|||
} |
|||
|
|||
#[allow(dead_code)] |
|||
pub(crate) fn to_us(&self) -> String { |
|||
let tmp = self.picos as f64 / (1_000_000 as f64); |
|||
format!("{:.03}us", tmp) |
|||
} |
|||
|
|||
#[allow(dead_code)] |
|||
pub(crate) fn to_ms(&self) -> String { |
|||
let tmp = self.picos as f64 / (1_000_000_000 as f64); |
|||
format!("{:.03}ms", tmp) |
|||
} |
|||
|
|||
#[allow(dead_code)] |
|||
pub(crate) fn to_s(&self) -> String { |
|||
let tmp = self.picos as f64 / (1_000_000_000_000 as i64 as f64); |
|||
format!("{:.03}s", tmp) |
|||
} |
|||
} |
@ -0,0 +1,41 @@ |
|||
use super::Duration; |
|||
use crate::core::Core; |
|||
use std::cmp::Ordering; |
|||
|
|||
pub(crate) fn preparation() { |
|||
unsafe { |
|||
Core::benchmark_preparation(); |
|||
} |
|||
} |
|||
|
|||
pub(crate) fn warm_up(count: u64) -> Duration { |
|||
unsafe { |
|||
Duration::from_us(Core::benchmark_warm_up_us(count)) |
|||
} |
|||
} |
|||
|
|||
pub(crate) fn range_flip() -> Duration { |
|||
unsafe { |
|||
Duration::from_ns(Core::benchmark_range_flip_ns()) |
|||
} |
|||
} |
|||
|
|||
pub(crate) fn basic_ranges() -> Result<Duration, &'static str> { |
|||
unsafe { |
|||
let time = Core::benchmark_basic_ranges_ms(); |
|||
match time.total_cmp(&(0 as f64)) { |
|||
Ordering::Greater => Ok(Duration::from_ms(time)), |
|||
_ => Err("data already built"), |
|||
} |
|||
} |
|||
} |
|||
|
|||
pub(crate) fn all_cases() -> Result<Duration, &'static str> { |
|||
unsafe { |
|||
let time = Core::benchmark_all_cases_ms(); |
|||
match time.total_cmp(&(0 as f64)) { |
|||
Ordering::Greater => Ok(Duration::from_ms(time)), |
|||
_ => Err("data already built"), |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,18 @@ |
|||
mod ffi; |
|||
|
|||
mod chore; |
|||
|
|||
use chore::Duration; |
|||
|
|||
use ffi::*; |
|||
|
|||
pub fn demo() { |
|||
|
|||
println!("warm up: {}", warm_up(0x100_0000).to_ms()); |
|||
|
|||
println!("range flip: {}", range_flip().to_ns()); |
|||
|
|||
println!("basic ranges: {}", basic_ranges().unwrap().to_ms()); |
|||
println!("all cases: {}", all_cases().unwrap().to_ms()); |
|||
|
|||
} |
Loading…
Reference in new issue