Use std time
This commit is contained in:
parent
dc356ffef7
commit
656edbf0f0
19
Cargo.lock
generated
19
Cargo.lock
generated
@ -159,11 +159,6 @@ name = "quote"
|
||||
version = "0.3.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "redox_syscall"
|
||||
version = "0.1.32"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "0.2.3"
|
||||
@ -203,7 +198,6 @@ dependencies = [
|
||||
"serde_derive 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_json 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"term 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"time 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"toml 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"unicode-segmentation 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -294,17 +288,6 @@ dependencies = [
|
||||
"unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "time"
|
||||
version = "0.1.38"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.34 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"redox_syscall 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml"
|
||||
version = "0.4.5"
|
||||
@ -374,7 +357,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
"checksum memchr 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "796fba70e76612589ed2ce7f45282f5af869e0fdd7cc6199fa1aa1f1d591ba9d"
|
||||
"checksum num-traits 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)" = "cacfcab5eb48250ee7d0c7896b51a2c5eec99c1feea5f32025635f5ae4b00070"
|
||||
"checksum quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a"
|
||||
"checksum redox_syscall 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)" = "ab105df655884ede59d45b7070c8a65002d921461ee813a024558ca16030eea0"
|
||||
"checksum regex 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ac6ab4e9218ade5b423358bbd2567d1617418403c7a512603630181813316322"
|
||||
"checksum regex-syntax 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ad890a5eef7953f55427c50575c680c42841653abd2b028b68cd223d157f62db"
|
||||
"checksum rustc-demangle 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "aee45432acc62f7b9a108cc054142dac51f979e69e71ddce7d6fc7adf29e817e"
|
||||
@ -388,7 +370,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
"checksum synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a393066ed9010ebaed60b9eafa373d4b1baac186dd7e008555b0f702b51945b6"
|
||||
"checksum term 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "fa63644f74ce96fbeb9b794f66aff2a52d601cbd5e80f4b97123e3899f4570f1"
|
||||
"checksum thread_local 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "279ef31c19ededf577bfd12dfae728040a21f635b06a24cd670ff510edd38963"
|
||||
"checksum time 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)" = "d5d788d3aa77bc0ef3e9621256885555368b47bd495c13dd2e7413c89f845520"
|
||||
"checksum toml 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)" = "a7540f4ffc193e0d3c94121edb19b055670d369f77d5804db11ae053a45b6e7e"
|
||||
"checksum unicode-segmentation 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a8083c594e02b8ae1654ae26f0ade5158b119bd88ad0e8227a5d8fcd72407946"
|
||||
"checksum unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f860d7d29cf02cb2f3f359fd35991af3d30bac52c57d265a3c461074cb4dc"
|
||||
|
@ -44,7 +44,6 @@ env_logger = "0.4"
|
||||
getopts = "0.2"
|
||||
derive-new = "0.5"
|
||||
cargo_metadata = "0.4"
|
||||
time = "0.1"
|
||||
|
||||
[target.'cfg(unix)'.dependencies]
|
||||
libc = "0.2.11"
|
||||
|
12
src/lib.rs
12
src/lib.rs
@ -23,7 +23,6 @@
|
||||
extern crate serde_json;
|
||||
extern crate syntax;
|
||||
extern crate term;
|
||||
extern crate time;
|
||||
extern crate unicode_segmentation;
|
||||
|
||||
use std::collections::HashMap;
|
||||
@ -32,6 +31,7 @@
|
||||
use std::iter::repeat;
|
||||
use std::path::PathBuf;
|
||||
use std::rc::Rc;
|
||||
use std::time::Duration;
|
||||
|
||||
use errors::{DiagnosticBuilder, Handler};
|
||||
use errors::emitter::{ColorConfig, EmitterWriter};
|
||||
@ -655,10 +655,14 @@ pub fn format_input<T: Write>(
|
||||
summary.mark_format_time();
|
||||
|
||||
if config.verbose() {
|
||||
fn duration_to_f32(d: Duration) -> f32 {
|
||||
d.as_secs() as f32 + d.subsec_nanos() as f32 / 1_000_000_000f32
|
||||
}
|
||||
|
||||
println!(
|
||||
"Spent {} in the parsing phase, and {} in the formatting phase",
|
||||
summary.get_parse_time().unwrap(),
|
||||
summary.get_format_time().unwrap(),
|
||||
"Spent {0:.3} secs in the parsing phase, and {1:.3} secs in the formatting phase",
|
||||
duration_to_f32(summary.get_parse_time().unwrap()),
|
||||
duration_to_f32(summary.get_format_time().unwrap()),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
use time::{precise_time_ns, Duration};
|
||||
use std::time::{Duration, Instant};
|
||||
use std::default::Default;
|
||||
|
||||
#[must_use]
|
||||
@ -33,8 +33,8 @@ pub fn mark_format_time(&mut self) {
|
||||
pub fn get_parse_time(&self) -> Option<Duration> {
|
||||
match self.timer {
|
||||
Timer::DoneParsing(init, parse_time) | Timer::DoneFormatting(init, parse_time, _) => {
|
||||
// This should never underflow since `precise_time_ns()` guarantees monotonicity.
|
||||
Some(Duration::nanoseconds((parse_time - init) as i64))
|
||||
// This should never underflow since `Instant::now()` guarantees monotonicity.
|
||||
Some(parse_time.duration_since(init))
|
||||
}
|
||||
Timer::Initialized(..) => None,
|
||||
}
|
||||
@ -45,7 +45,7 @@ pub fn get_parse_time(&self) -> Option<Duration> {
|
||||
pub fn get_format_time(&self) -> Option<Duration> {
|
||||
match self.timer {
|
||||
Timer::DoneFormatting(_init, parse_time, format_time) => {
|
||||
Some(Duration::nanoseconds((format_time - parse_time) as i64))
|
||||
Some(format_time.duration_since(parse_time))
|
||||
}
|
||||
Timer::DoneParsing(..) | Timer::Initialized(..) => None,
|
||||
}
|
||||
@ -104,21 +104,21 @@ pub fn print_exit_codes() {
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
enum Timer {
|
||||
Initialized(u64),
|
||||
DoneParsing(u64, u64),
|
||||
DoneFormatting(u64, u64, u64),
|
||||
Initialized(Instant),
|
||||
DoneParsing(Instant, Instant),
|
||||
DoneFormatting(Instant, Instant, Instant),
|
||||
}
|
||||
|
||||
impl Default for Timer {
|
||||
fn default() -> Self {
|
||||
Timer::Initialized(precise_time_ns())
|
||||
Timer::Initialized(Instant::now())
|
||||
}
|
||||
}
|
||||
|
||||
impl Timer {
|
||||
fn done_parsing(self) -> Self {
|
||||
match self {
|
||||
Timer::Initialized(init_time) => Timer::DoneParsing(init_time, precise_time_ns()),
|
||||
Timer::Initialized(init_time) => Timer::DoneParsing(init_time, Instant::now()),
|
||||
_ => panic!("Timer can only transition to DoneParsing from Initialized state"),
|
||||
}
|
||||
}
|
||||
@ -126,7 +126,7 @@ fn done_parsing(self) -> Self {
|
||||
fn done_formatting(self) -> Self {
|
||||
match self {
|
||||
Timer::DoneParsing(init_time, parse_time) => {
|
||||
Timer::DoneFormatting(init_time, parse_time, precise_time_ns())
|
||||
Timer::DoneFormatting(init_time, parse_time, Instant::now())
|
||||
}
|
||||
_ => panic!("Timer can only transition to DoneFormatting from DoneParsing state"),
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user