mirror of
https://github.com/sharkdp/hyperfine.git
synced 2026-10-30 16:40:18 +00:00
Refactor timer module
This commit is contained in:
1 parent
f029a46ff9
commit
defafdf707
6 files changed
+18
-73
No files matched your search
+5
-18
@@ -1,35 +1,22 @@
|
||||
#![cfg(not(windows))]
|
||||
|
||||
use std::mem;
|
||||
use std::process::Child;
|
||||
|
||||
use crate::timer::{CPUInterval, CPUTimes, TimerStart, TimerStop};
|
||||
use crate::timer::{CPUInterval, CPUTimes};
|
||||
use crate::util::units::Second;
|
||||
|
||||
pub fn get_cpu_timer() -> Box<dyn TimerStop<Result = (Second, Second)>> {
|
||||
Box::new(CPUTimer::start())
|
||||
}
|
||||
|
||||
struct CPUTimer {
|
||||
pub struct CPUTimer {
|
||||
start_cpu: CPUTimes,
|
||||
}
|
||||
|
||||
impl TimerStart for CPUTimer {
|
||||
fn start() -> Self {
|
||||
impl CPUTimer {
|
||||
pub fn start() -> Self {
|
||||
CPUTimer {
|
||||
start_cpu: get_cpu_times(),
|
||||
}
|
||||
}
|
||||
|
||||
fn start_for_process(_: &Child) -> Self {
|
||||
Self::start()
|
||||
}
|
||||
}
|
||||
|
||||
impl TimerStop for CPUTimer {
|
||||
type Result = (Second, Second);
|
||||
|
||||
fn stop(&self) -> Self::Result {
|
||||
pub fn stop(&self) -> (Second, Second) {
|
||||
let end_cpu = get_cpu_times();
|
||||
let cpu_interval = cpu_time_interval(&self.start_cpu, &end_cpu);
|
||||
(cpu_interval.user, cpu_interval.system)
|
||||
|
||||
Reference in new issue
Block a user