diff --git a/Cargo.lock b/Cargo.lock index e06a012..30b00c9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -153,7 +153,6 @@ dependencies = [ "indicatif 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)", "statistical 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", @@ -462,6 +461,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" name = "serde" version = "1.0.91" source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "serde_derive 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", +] [[package]] name = "serde_derive" diff --git a/Cargo.toml b/Cargo.toml index 5fbcb1b..9395e3e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,6 +8,7 @@ name = "hyperfine" readme = "README.md" repository = "https://github.com/sharkdp/hyperfine" version = "1.5.0" +edition = "2018" [dependencies] colored = "1.7" @@ -16,8 +17,7 @@ statistical = "1.0" atty = "0.2.2" cfg-if = "0.1.7" csv = "1.0.7" -serde = "1.0.91" -serde_derive = "1.0.90" +serde = { version = "1.0.91", features = ["derive"] } serde_json = "1.0.39" [target.'cfg(not(windows))'.dependencies] diff --git a/src/hyperfine/app.rs b/src/hyperfine/app.rs index 32e0921..b24d38a 100644 --- a/src/hyperfine/app.rs +++ b/src/hyperfine/app.rs @@ -1,6 +1,6 @@ use atty; use atty::Stream; -use clap::{App, AppSettings, Arg, ArgMatches}; +use clap::{crate_version, App, AppSettings, Arg, ArgMatches}; use std::ffi::OsString; pub fn get_arg_matches(args: T) -> ArgMatches<'static> diff --git a/src/hyperfine/benchmark.rs b/src/hyperfine/benchmark.rs index edd0a41..890fde5 100644 --- a/src/hyperfine/benchmark.rs +++ b/src/hyperfine/benchmark.rs @@ -5,17 +5,17 @@ use std::process::Stdio; use colored::*; use statistical::{mean, standard_deviation}; -use hyperfine::format::{format_duration, format_duration_unit}; -use hyperfine::internal::{get_progress_bar, max, min, MIN_EXECUTION_TIME}; -use hyperfine::outlier_detection::{modified_zscores, OUTLIER_THRESHOLD}; -use hyperfine::shell::execute_and_time; -use hyperfine::timer::wallclocktimer::WallClockTimer; -use hyperfine::timer::{TimerStart, TimerStop}; -use hyperfine::types::{ +use crate::hyperfine::format::{format_duration, format_duration_unit}; +use crate::hyperfine::internal::{get_progress_bar, max, min, MIN_EXECUTION_TIME}; +use crate::hyperfine::outlier_detection::{modified_zscores, OUTLIER_THRESHOLD}; +use crate::hyperfine::shell::execute_and_time; +use crate::hyperfine::timer::wallclocktimer::WallClockTimer; +use crate::hyperfine::timer::{TimerStart, TimerStop}; +use crate::hyperfine::types::{ BenchmarkResult, CmdFailureAction, Command, HyperfineOptions, OutputStyleOption, }; -use hyperfine::units::Second; -use hyperfine::warnings::Warnings; +use crate::hyperfine::units::Second; +use crate::hyperfine::warnings::Warnings; /// Results from timing a single shell command #[derive(Debug, Default, Copy, Clone)] @@ -42,7 +42,7 @@ fn subtract_shell_spawning_time(time: Second, shell_spawning_time: Second) -> Se /// Run the given shell command and measure the execution time pub fn time_shell_command( shell: &str, - command: &Command, + command: &Command<'_>, show_output: bool, failure_action: CmdFailureAction, shell_spawning_time: Option, @@ -146,7 +146,7 @@ pub fn mean_shell_spawning_time( fn run_intermediate_command( shell: &str, - command: &Option, + command: &Option>, show_output: bool, error_output: &'static str, ) -> io::Result { @@ -165,7 +165,7 @@ fn run_intermediate_command( /// Run the command specified by `--prepare`. fn run_preparation_command( shell: &str, - command: &Option, + command: &Option>, show_output: bool, ) -> io::Result { let error_output = "The preparation command terminated with a non-zero exit code. \ @@ -177,7 +177,7 @@ fn run_preparation_command( /// Run the command specified by `--cleanup`. fn run_cleanup_command( shell: &str, - command: &Option, + command: &Option>, show_output: bool, ) -> io::Result { let error_output = "The cleanup command terminated with a non-zero exit code. \ @@ -189,7 +189,7 @@ fn run_cleanup_command( /// Run the benchmark for a single shell command pub fn run_benchmark( num: usize, - cmd: &Command, + cmd: &Command<'_>, shell_spawning_time: TimingResult, options: &HyperfineOptions, ) -> io::Result { diff --git a/src/hyperfine/error.rs b/src/hyperfine/error.rs index 033cc4f..d1fe060 100644 --- a/src/hyperfine/error.rs +++ b/src/hyperfine/error.rs @@ -16,7 +16,7 @@ impl From for ParameterScanError { } impl fmt::Display for ParameterScanError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.description()) } } @@ -38,7 +38,7 @@ pub enum OptionsError { } impl fmt::Display for OptionsError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.description()) } } diff --git a/src/hyperfine/export/asciidoc.rs b/src/hyperfine/export/asciidoc.rs index f2d053e..81d6c68 100644 --- a/src/hyperfine/export/asciidoc.rs +++ b/src/hyperfine/export/asciidoc.rs @@ -1,8 +1,8 @@ use super::Exporter; -use hyperfine::format::format_duration_value; -use hyperfine::types::BenchmarkResult; -use hyperfine::units::Unit; +use crate::hyperfine::format::format_duration_value; +use crate::hyperfine::types::BenchmarkResult; +use crate::hyperfine::units::Unit; use std::io::Result; diff --git a/src/hyperfine/export/csv.rs b/src/hyperfine/export/csv.rs index 57c0bef..8b611e6 100644 --- a/src/hyperfine/export/csv.rs +++ b/src/hyperfine/export/csv.rs @@ -1,7 +1,7 @@ use super::Exporter; -use hyperfine::types::BenchmarkResult; -use hyperfine::units::Unit; +use crate::hyperfine::types::BenchmarkResult; +use crate::hyperfine::units::Unit; use std::io::{Error, ErrorKind, Result}; diff --git a/src/hyperfine/export/json.rs b/src/hyperfine/export/json.rs index 62a3f50..01da670 100644 --- a/src/hyperfine/export/json.rs +++ b/src/hyperfine/export/json.rs @@ -1,9 +1,10 @@ use super::Exporter; -use hyperfine::types::BenchmarkResult; -use hyperfine::units::Unit; +use crate::hyperfine::types::BenchmarkResult; +use crate::hyperfine::units::Unit; use std::io::{Error, ErrorKind, Result}; +use serde::*; use serde_json::to_vec_pretty; #[derive(Serialize, Debug)] diff --git a/src/hyperfine/export/markdown.rs b/src/hyperfine/export/markdown.rs index 930b10c..4acef23 100644 --- a/src/hyperfine/export/markdown.rs +++ b/src/hyperfine/export/markdown.rs @@ -1,8 +1,8 @@ use super::Exporter; -use hyperfine::format::format_duration_value; -use hyperfine::types::BenchmarkResult; -use hyperfine::units::Unit; +use crate::hyperfine::format::format_duration_value; +use crate::hyperfine::types::BenchmarkResult; +use crate::hyperfine::units::Unit; use std::io::Result; diff --git a/src/hyperfine/export/mod.rs b/src/hyperfine/export/mod.rs index f8c06fd..d6825e3 100644 --- a/src/hyperfine/export/mod.rs +++ b/src/hyperfine/export/mod.rs @@ -11,8 +11,8 @@ use self::markdown::MarkdownExporter; use std::fs::File; use std::io::{Result, Write}; -use hyperfine::types::BenchmarkResult; -use hyperfine::units::Unit; +use crate::hyperfine::types::BenchmarkResult; +use crate::hyperfine::units::Unit; /// The desired form of exporter to use for a given file. #[derive(Clone)] @@ -37,7 +37,7 @@ trait Exporter { } struct ExporterWithFilename { - exporter: Box, + exporter: Box, filename: String, } @@ -56,7 +56,7 @@ impl ExportManager { /// Add an additional exporter to the ExportManager pub fn add_exporter(&mut self, export_type: ExportType, filename: &str) { - let exporter: Box = match export_type { + let exporter: Box = match export_type { ExportType::Asciidoc => Box::new(AsciidocExporter::default()), ExportType::Csv => Box::new(CsvExporter::default()), ExportType::Json => Box::new(JsonExporter::default()), diff --git a/src/hyperfine/format.rs b/src/hyperfine/format.rs index 08f0c61..1204c46 100644 --- a/src/hyperfine/format.rs +++ b/src/hyperfine/format.rs @@ -1,4 +1,4 @@ -use hyperfine::units::{Second, Unit}; +use crate::hyperfine::units::{Second, Unit}; /// Format the given duration as a string. The output-unit can be enforced by setting `unit` to /// `Some(target_unit)`. If `unit` is `None`, it will be determined automatically. diff --git a/src/hyperfine/internal.rs b/src/hyperfine/internal.rs index 51ea152..fd8157a 100644 --- a/src/hyperfine/internal.rs +++ b/src/hyperfine/internal.rs @@ -1,8 +1,8 @@ use colored::*; use indicatif::{ProgressBar, ProgressStyle}; -use hyperfine::types::{BenchmarkResult, OutputStyleOption}; -use hyperfine::units::Second; +use crate::hyperfine::types::{BenchmarkResult, OutputStyleOption}; +use crate::hyperfine::units::Second; use std::cmp::Ordering; use std::iter::Iterator; diff --git a/src/hyperfine/shell.rs b/src/hyperfine/shell.rs index 543bc21..7a84381 100644 --- a/src/hyperfine/shell.rs +++ b/src/hyperfine/shell.rs @@ -2,7 +2,7 @@ use std; use std::io; use std::process::{Command, ExitStatus, Stdio}; -use hyperfine::timer::get_cpu_timer; +use crate::hyperfine::timer::get_cpu_timer; /// Used to indicate the result of running a command #[derive(Debug, Copy, Clone)] diff --git a/src/hyperfine/timer/internal.rs b/src/hyperfine/timer/internal.rs index 49ef3ce..ec3b572 100644 --- a/src/hyperfine/timer/internal.rs +++ b/src/hyperfine/timer/internal.rs @@ -1,4 +1,4 @@ -use hyperfine::units::Second; +use crate::hyperfine::units::Second; #[derive(Debug, Copy, Clone)] pub struct CPUTimes { diff --git a/src/hyperfine/timer/mod.rs b/src/hyperfine/timer/mod.rs index 9fe26bf..68e0ef7 100644 --- a/src/hyperfine/timer/mod.rs +++ b/src/hyperfine/timer/mod.rs @@ -2,6 +2,8 @@ mod internal; pub mod wallclocktimer; +use cfg_if::cfg_if; + cfg_if! { if #[cfg(windows)] { mod windows_timer; diff --git a/src/hyperfine/timer/unix_timer.rs b/src/hyperfine/timer/unix_timer.rs index 8d940dd..f65b207 100644 --- a/src/hyperfine/timer/unix_timer.rs +++ b/src/hyperfine/timer/unix_timer.rs @@ -1,13 +1,13 @@ #![cfg(not(windows))] use super::internal::{CPUInterval, CPUTimes}; -use hyperfine::timer::{TimerStart, TimerStop}; -use hyperfine::units::Second; +use crate::hyperfine::timer::{TimerStart, TimerStop}; +use crate::hyperfine::units::Second; use std::mem; use std::process::Child; -pub fn get_cpu_timer() -> Box> { +pub fn get_cpu_timer() -> Box> { Box::new(CPUTimer::start()) } @@ -66,6 +66,9 @@ fn cpu_time_interval(start: &CPUTimes, end: &CPUTimes) -> CPUInterval { } } +#[cfg(test)] +use approx::assert_relative_eq; + #[test] fn test_cpu_time_interval() { let t_a = CPUTimes { diff --git a/src/hyperfine/timer/wallclocktimer.rs b/src/hyperfine/timer/wallclocktimer.rs index b28a24e..8b8a14b 100644 --- a/src/hyperfine/timer/wallclocktimer.rs +++ b/src/hyperfine/timer/wallclocktimer.rs @@ -1,8 +1,8 @@ use std::process::Child; use std::time::Instant; -use hyperfine::timer::{TimerStart, TimerStop}; -use hyperfine::units::Second; +use crate::hyperfine::timer::{TimerStart, TimerStop}; +use crate::hyperfine::units::Second; pub struct WallClockTimer { start: Instant, diff --git a/src/hyperfine/timer/windows_timer.rs b/src/hyperfine/timer/windows_timer.rs index 4471e8d..2ddfc95 100644 --- a/src/hyperfine/timer/windows_timer.rs +++ b/src/hyperfine/timer/windows_timer.rs @@ -1,8 +1,8 @@ #![cfg(windows)] use super::internal::CPUTimes; -use hyperfine::timer::{TimerStart, TimerStop}; -use hyperfine::units::Second; +use crate::hyperfine::timer::{TimerStart, TimerStop}; +use crate::hyperfine::units::Second; use winapi::um::processthreadsapi::GetProcessTimes; use winapi::um::winnt::HANDLE; diff --git a/src/hyperfine/types.rs b/src/hyperfine/types.rs index 784af51..fbd71aa 100644 --- a/src/hyperfine/types.rs +++ b/src/hyperfine/types.rs @@ -1,7 +1,8 @@ /// This module contains common internal types. +use serde::*; use std::fmt; -use hyperfine::units::{Second, Unit}; +use crate::hyperfine::units::{Second, Unit}; #[cfg(not(windows))] pub const DEFAULT_SHELL: &str = "sh"; @@ -50,7 +51,7 @@ impl<'a> Command<'a> { } impl<'a> fmt::Display for Command<'a> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.get_shell_command()) } } diff --git a/src/hyperfine/warnings.rs b/src/hyperfine/warnings.rs index d14df60..95a3e16 100644 --- a/src/hyperfine/warnings.rs +++ b/src/hyperfine/warnings.rs @@ -1,8 +1,8 @@ use std::fmt; -use hyperfine::format::format_duration; -use hyperfine::internal::MIN_EXECUTION_TIME; -use hyperfine::units::Second; +use crate::hyperfine::format::format_duration; +use crate::hyperfine::internal::MIN_EXECUTION_TIME; +use crate::hyperfine::units::Second; /// A list of all possible warnings pub enum Warnings { @@ -13,7 +13,7 @@ pub enum Warnings { } impl fmt::Display for Warnings { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match *self { Warnings::FastExecutionTime => write!( f, diff --git a/src/main.rs b/src/main.rs index 730cd4a..743289a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,33 +1,3 @@ -extern crate atty; - -#[macro_use] -extern crate cfg_if; - -#[macro_use] -extern crate clap; -extern crate colored; -extern crate csv; -extern crate indicatif; -extern crate serde; - -#[macro_use] -extern crate serde_derive; -extern crate serde_json; -extern crate statistical; - -// Os-specific dependencies -cfg_if! { - if #[cfg(windows)] { - extern crate winapi; - } else { - extern crate libc; - } -} - -#[cfg(test)] -#[macro_use] -extern crate approx; - use std::cmp; use std::env; use std::error::Error; @@ -40,15 +10,15 @@ use colored::*; mod hyperfine; -use hyperfine::app::get_arg_matches; -use hyperfine::benchmark::{mean_shell_spawning_time, run_benchmark}; -use hyperfine::error::{OptionsError, ParameterScanError}; -use hyperfine::export::{ExportManager, ExportType}; -use hyperfine::internal::write_benchmark_comparison; -use hyperfine::types::{ +use crate::hyperfine::app::get_arg_matches; +use crate::hyperfine::benchmark::{mean_shell_spawning_time, run_benchmark}; +use crate::hyperfine::error::{OptionsError, ParameterScanError}; +use crate::hyperfine::export::{ExportManager, ExportType}; +use crate::hyperfine::internal::write_benchmark_comparison; +use crate::hyperfine::types::{ BenchmarkResult, CmdFailureAction, Command, HyperfineOptions, OutputStyleOption, }; -use hyperfine::units::Unit; +use crate::hyperfine::units::Unit; /// Print error message to stderr and terminate pub fn error(message: &str) -> ! { @@ -57,7 +27,7 @@ pub fn error(message: &str) -> ! { } /// Runs the benchmark for the given commands -fn run(commands: &Vec, options: &HyperfineOptions) -> io::Result> { +fn run(commands: &Vec>, options: &HyperfineOptions) -> io::Result> { let shell_spawning_time = mean_shell_spawning_time(&options.shell, &options.output_style, options.show_output)?; @@ -118,7 +88,7 @@ fn main() { } /// Build the HyperfineOptions that correspond to the given ArgMatches -fn build_hyperfine_options(matches: &ArgMatches) -> Result { +fn build_hyperfine_options(matches: &ArgMatches<'_>) -> Result { let mut options = HyperfineOptions::default(); let str_to_u64 = |n| u64::from_str_radix(n, 10).ok(); @@ -214,7 +184,7 @@ fn build_hyperfine_options(matches: &ArgMatches) -> Result ExportManager { +fn build_export_manager(matches: &ArgMatches<'_>) -> ExportManager { let mut export_manager = ExportManager::new(); { let mut add_exporter = |flag, exporttype| { @@ -231,7 +201,7 @@ fn build_export_manager(matches: &ArgMatches) -> ExportManager { } /// Build the commands to benchmark -fn build_commands<'a>(matches: &'a ArgMatches) -> Vec> { +fn build_commands<'a>(matches: &'a ArgMatches<'_>) -> Vec> { let command_strings = matches.values_of("command").unwrap(); let commands = if let Some(args) = matches.values_of("parameter-scan") {