mirror of
https://github.com/sharkdp/hyperfine.git
synced 2026-10-30 00:38:56 +00:00
convert to rust edition 2018
This commit is contained in:
1 parent
a6f61a6bda
commit
2d0b0488f2
21 files changed
+72
-93
No files matched your search
Generated
+3
-1
@@ -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"
|
||||
|
||||
+2
-2
@@ -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]
|
||||
|
||||
@@ -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<T>(args: T) -> ArgMatches<'static>
|
||||
|
||||
+14
-14
@@ -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<TimingResult>,
|
||||
@@ -146,7 +146,7 @@ pub fn mean_shell_spawning_time(
|
||||
|
||||
fn run_intermediate_command(
|
||||
shell: &str,
|
||||
command: &Option<Command>,
|
||||
command: &Option<Command<'_>>,
|
||||
show_output: bool,
|
||||
error_output: &'static str,
|
||||
) -> io::Result<TimingResult> {
|
||||
@@ -165,7 +165,7 @@ fn run_intermediate_command(
|
||||
/// Run the command specified by `--prepare`.
|
||||
fn run_preparation_command(
|
||||
shell: &str,
|
||||
command: &Option<Command>,
|
||||
command: &Option<Command<'_>>,
|
||||
show_output: bool,
|
||||
) -> io::Result<TimingResult> {
|
||||
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>,
|
||||
command: &Option<Command<'_>>,
|
||||
show_output: bool,
|
||||
) -> io::Result<TimingResult> {
|
||||
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<BenchmarkResult> {
|
||||
|
||||
@@ -16,7 +16,7 @@ impl From<num::ParseIntError> 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())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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};
|
||||
|
||||
|
||||
@@ -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)]
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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>,
|
||||
exporter: Box<dyn Exporter>,
|
||||
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<Exporter> = match export_type {
|
||||
let exporter: Box<dyn Exporter> = match export_type {
|
||||
ExportType::Asciidoc => Box::new(AsciidocExporter::default()),
|
||||
ExportType::Csv => Box::new(CsvExporter::default()),
|
||||
ExportType::Json => Box::new(JsonExporter::default()),
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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)]
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use hyperfine::units::Second;
|
||||
use crate::hyperfine::units::Second;
|
||||
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct CPUTimes {
|
||||
|
||||
@@ -2,6 +2,8 @@ mod internal;
|
||||
|
||||
pub mod wallclocktimer;
|
||||
|
||||
use cfg_if::cfg_if;
|
||||
|
||||
cfg_if! {
|
||||
if #[cfg(windows)] {
|
||||
mod windows_timer;
|
||||
|
||||
@@ -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<TimerStop<Result = (Second, Second)>> {
|
||||
pub fn get_cpu_timer() -> Box<dyn TimerStop<Result = (Second, Second)>> {
|
||||
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 {
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
+11
-41
@@ -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<Command>, options: &HyperfineOptions) -> io::Result<Vec<BenchmarkResult>> {
|
||||
fn run(commands: &Vec<Command<'_>>, options: &HyperfineOptions) -> io::Result<Vec<BenchmarkResult>> {
|
||||
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<HyperfineOptions, OptionsError> {
|
||||
fn build_hyperfine_options(matches: &ArgMatches<'_>) -> Result<HyperfineOptions, OptionsError> {
|
||||
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<HyperfineOptions, Opt
|
||||
|
||||
/// Build the ExportManager that will export the results specified
|
||||
/// in the given ArgMatches
|
||||
fn build_export_manager(matches: &ArgMatches) -> 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<Command<'a>> {
|
||||
fn build_commands<'a>(matches: &'a ArgMatches<'_>) -> Vec<Command<'a>> {
|
||||
let command_strings = matches.values_of("command").unwrap();
|
||||
|
||||
let commands = if let Some(args) = matches.values_of("parameter-scan") {
|
||||
|
||||
Reference in new issue
Block a user