Skip to content
Myr

convert to rust edition 2018

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Andrii Radyk · committed by David Peter · parent a6f61a6 · Browse files · 21 files+72 added−93 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

21 files+72 added−93 removed

  • other:+72 added−93 removed

21 files+72 added−93 removed

modified:src/hyperfine/export/asciidoc.rs+3 added-3 removed
1use super::Exporter;23use hyperfine::format::format_duration_value;4use hyperfine::types::BenchmarkResult;5use hyperfine::units::Unit;3use crate::hyperfine::format::format_duration_value;4use crate::hyperfine::types::BenchmarkResult;5use crate::hyperfine::units::Unit;67use std::io::Result;89#[derive(Default)]
207 unmodified lines
modified:src/hyperfine/export/csv.rs+2 added-2 removed
1use super::Exporter;23use hyperfine::types::BenchmarkResult;4use hyperfine::units::Unit;3use crate::hyperfine::types::BenchmarkResult;4use crate::hyperfine::units::Unit;56use std::io::{Error, ErrorKind, Result};78use csv::WriterBuilder;
20 unmodified lines
modified:src/hyperfine/export/json.rs+3 added-2 removed
1use super::Exporter;2use hyperfine::types::BenchmarkResult;3use hyperfine::units::Unit;2use crate::hyperfine::types::BenchmarkResult;3use crate::hyperfine::units::Unit;45use std::io::{Error, ErrorKind, Result};67use serde::*;8use serde_json::to_vec_pretty;910#[derive(Serialize, Debug)]11struct HyperfineSummary<'a> {
16 unmodified lines
modified:src/hyperfine/export/markdown.rs+3 added-3 removed
1use super::Exporter;23use hyperfine::format::format_duration_value;4use hyperfine::types::BenchmarkResult;5use hyperfine::units::Unit;3use crate::hyperfine::format::format_duration_value;4use crate::hyperfine::types::BenchmarkResult;5use crate::hyperfine::units::Unit;67use std::io::Result;89#[derive(Default)]
247 unmodified lines
modified:src/hyperfine/export/mod.rs+4 added-4 removed
9 unmodified lines
1011use std::fs::File;12use std::io::{Result, Write};1314use hyperfine::types::BenchmarkResult;15use hyperfine::units::Unit;14use crate::hyperfine::types::BenchmarkResult;15use crate::hyperfine::units::Unit;1617/// The desired form of exporter to use for a given file.18#[derive(Clone)]19pub enum ExportType {
16 unmodified lines
36 fn serialize(&self, results: &Vec<BenchmarkResult>, unit: Option<Unit>) -> Result<Vec<u8>>;37}3839struct ExporterWithFilename {40 exporter: Box<Exporter>,40 exporter: Box<dyn Exporter>,41 filename: String,42}4344/// Handles the management of multiple file exporters.
10 unmodified lines
55 }5657 /// Add an additional exporter to the ExportManager58 pub fn add_exporter(&mut self, export_type: ExportType, filename: &str) {59 let exporter: Box<Exporter> = match export_type {59 let exporter: Box<dyn Exporter> = match export_type {60 ExportType::Asciidoc => Box::new(AsciidocExporter::default()),61 ExportType::Csv => Box::new(CsvExporter::default()),62 ExportType::Json => Box::new(JsonExporter::default()),63 ExportType::Markdown => Box::new(MarkdownExporter::default()),
22 unmodified lines
modified:src/hyperfine/timer/internal.rs+1 added-1 removed
1use hyperfine::units::Second;1use crate::hyperfine::units::Second;23#[derive(Debug, Copy, Clone)]4pub struct CPUTimes {5 /// Total amount of time spent executing in user mode
14 unmodified lines
modified:src/hyperfine/timer/mod.rs+2 added
1mod internal;23pub mod wallclocktimer;45use cfg_if::cfg_if;67cfg_if! {8 if #[cfg(windows)] {9 mod windows_timer;10 pub use self::windows_timer::get_cpu_timer;
18 unmodified lines
modified:src/hyperfine/timer/unix_timer.rs+6 added-3 removed
1#![cfg(not(windows))]23use super::internal::{CPUInterval, CPUTimes};4use hyperfine::timer::{TimerStart, TimerStop};5use hyperfine::units::Second;4use crate::hyperfine::timer::{TimerStart, TimerStop};5use crate::hyperfine::units::Second;67use std::mem;8use std::process::Child;910pub fn get_cpu_timer() -> Box<TimerStop<Result = (Second, Second)>> {10pub fn get_cpu_timer() -> Box<dyn TimerStop<Result = (Second, Second)>> {11 Box::new(CPUTimer::start())12}1314struct CPUTimer {
50 unmodified lines
65 system: ((end.system_usec - start.system_usec) as f64) * 1e-6,66 }67}6869#[cfg(test)]70use approx::assert_relative_eq;7172#[test]73fn test_cpu_time_interval() {74 let t_a = CPUTimes {75 user_usec: 12345,
20 unmodified lines
modified:src/hyperfine/timer/wallclocktimer.rs+2 added-2 removed
1use std::process::Child;2use std::time::Instant;34use hyperfine::timer::{TimerStart, TimerStop};5use hyperfine::units::Second;4use crate::hyperfine::timer::{TimerStart, TimerStop};5use crate::hyperfine::units::Second;67pub struct WallClockTimer {8 start: Instant,9}
21 unmodified lines
modified:src/hyperfine/timer/windows_timer.rs+2 added-2 removed
1#![cfg(windows)]23use super::internal::CPUTimes;4use hyperfine::timer::{TimerStart, TimerStop};5use hyperfine::units::Second;4use crate::hyperfine::timer::{TimerStart, TimerStop};5use crate::hyperfine::units::Second;67use winapi::um::processthreadsapi::GetProcessTimes;8use winapi::um::winnt::HANDLE;9
73 unmodified lines
modified:src/hyperfine/app.rs+1 added-1 removed
1use atty;2use atty::Stream;3use clap::{App, AppSettings, Arg, ArgMatches};3use clap::{crate_version, App, AppSettings, Arg, ArgMatches};4use std::ffi::OsString;56pub fn get_arg_matches<T>(args: T) -> ArgMatches<'static>7where
183 unmodified lines
modified:src/hyperfine/benchmark.rs+14 added-14 removed
3 unmodified lines
45use colored::*;6use statistical::{mean, standard_deviation};78use hyperfine::format::{format_duration, format_duration_unit};9use hyperfine::internal::{get_progress_bar, max, min, MIN_EXECUTION_TIME};10use hyperfine::outlier_detection::{modified_zscores, OUTLIER_THRESHOLD};11use hyperfine::shell::execute_and_time;12use hyperfine::timer::wallclocktimer::WallClockTimer;13use hyperfine::timer::{TimerStart, TimerStop};14use hyperfine::types::{8use crate::hyperfine::format::{format_duration, format_duration_unit};9use crate::hyperfine::internal::{get_progress_bar, max, min, MIN_EXECUTION_TIME};10use crate::hyperfine::outlier_detection::{modified_zscores, OUTLIER_THRESHOLD};11use crate::hyperfine::shell::execute_and_time;12use crate::hyperfine::timer::wallclocktimer::WallClockTimer;13use crate::hyperfine::timer::{TimerStart, TimerStop};14use crate::hyperfine::types::{15 BenchmarkResult, CmdFailureAction, Command, HyperfineOptions, OutputStyleOption,16};17use hyperfine::units::Second;18use hyperfine::warnings::Warnings;17use crate::hyperfine::units::Second;18use crate::hyperfine::warnings::Warnings;1920/// Results from timing a single shell command21#[derive(Debug, Default, Copy, Clone)]22pub struct TimingResult {
18 unmodified lines
4142/// Run the given shell command and measure the execution time43pub fn time_shell_command(44 shell: &str,45 command: &Command,45 command: &Command<'_>,46 show_output: bool,47 failure_action: CmdFailureAction,48 shell_spawning_time: Option<TimingResult>,49) -> io::Result<(TimingResult, bool)> {
95 unmodified lines
145}146147fn run_intermediate_command(148 shell: &str,149 command: &Option<Command>,149 command: &Option<Command<'_>>,150 show_output: bool,151 error_output: &'static str,152) -> io::Result<TimingResult> {153 if let &Some(ref cmd) = command {
10 unmodified lines
164165/// Run the command specified by `--prepare`.166fn run_preparation_command(167 shell: &str,168 command: &Option<Command>,168 command: &Option<Command<'_>>,169 show_output: bool,170) -> io::Result<TimingResult> {171 let error_output = "The preparation command terminated with a non-zero exit code. \172 Append ' || true' to the command if you are sure that this can be ignored.";
3 unmodified lines
176177/// Run the command specified by `--cleanup`.178fn run_cleanup_command(179 shell: &str,180 command: &Option<Command>,180 command: &Option<Command<'_>>,181 show_output: bool,182) -> io::Result<TimingResult> {183 let error_output = "The cleanup command terminated with a non-zero exit code. \184 Append ' || true' to the command if you are sure that this can be ignored.";
3 unmodified lines
188189/// Run the benchmark for a single shell command190pub fn run_benchmark(191 num: usize,192 cmd: &Command,192 cmd: &Command<'_>,193 shell_spawning_time: TimingResult,194 options: &HyperfineOptions,195) -> io::Result<BenchmarkResult> {196 println!(
208 unmodified lines
modified:src/hyperfine/error.rs+2 added-2 removed
14 unmodified lines
15 }16}1718impl fmt::Display for ParameterScanError {19 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {19 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {20 write!(f, "{}", self.description())21 }22}23
13 unmodified lines
37 EmptyRunsRange,38}3940impl fmt::Display for OptionsError {41 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {41 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {42 write!(f, "{}", self.description())43 }44}45
8 unmodified lines
modified:src/hyperfine/format.rs+1 added-1 removed
1use hyperfine::units::{Second, Unit};1use crate::hyperfine::units::{Second, Unit};23/// Format the given duration as a string. The output-unit can be enforced by setting `unit` to4/// `Some(target_unit)`. If `unit` is `None`, it will be determined automatically.5pub fn format_duration(duration: Second, unit: Option<Unit>) -> String {
61 unmodified lines
modified:src/hyperfine/internal.rs+2 added-2 removed
1use colored::*;2use indicatif::{ProgressBar, ProgressStyle};34use hyperfine::types::{BenchmarkResult, OutputStyleOption};5use hyperfine::units::Second;4use crate::hyperfine::types::{BenchmarkResult, OutputStyleOption};5use crate::hyperfine::units::Second;67use std::cmp::Ordering;8use std::iter::Iterator;9
86 unmodified lines
modified:src/hyperfine/shell.rs+1 added-1 removed
1use std;2use std::io;3use std::process::{Command, ExitStatus, Stdio};45use hyperfine::timer::get_cpu_timer;5use crate::hyperfine::timer::get_cpu_timer;67/// Used to indicate the result of running a command8#[derive(Debug, Copy, Clone)]9pub struct ExecuteResult {
84 unmodified lines
modified:src/hyperfine/types.rs+3 added-2 removed
1/// This module contains common internal types.2use serde::*;3use std::fmt;44use hyperfine::units::{Second, Unit};5use crate::hyperfine::units::{Second, Unit};67#[cfg(not(windows))]8pub const DEFAULT_SHELL: &str = "sh";9
40 unmodified lines
50 }51}5253impl<'a> fmt::Display for Command<'a> {53 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {54 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {55 write!(f, "{}", self.get_shell_command())56 }57}58
150 unmodified lines
modified:src/hyperfine/warnings.rs+4 added-4 removed
1use std::fmt;23use hyperfine::format::format_duration;4use hyperfine::internal::MIN_EXECUTION_TIME;5use hyperfine::units::Second;3use crate::hyperfine::format::format_duration;4use crate::hyperfine::internal::MIN_EXECUTION_TIME;5use crate::hyperfine::units::Second;67/// A list of all possible warnings8pub enum Warnings {9 FastExecutionTime,
2 unmodified lines
12 OutliersDetected,13}1415impl fmt::Display for Warnings {16 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {16 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {17 match *self {18 Warnings::FastExecutionTime => write!(19 f,20 "Command took less than {:.0} ms to complete. Results might be inaccurate.",
21 unmodified lines
modified:src/main.rs+11 added-41 removed
1extern crate atty;23#[macro_use]4extern crate cfg_if;56#[macro_use]7extern crate clap;8extern crate colored;9extern crate csv;10extern crate indicatif;11extern crate serde;1213#[macro_use]14extern crate serde_derive;15extern crate serde_json;16extern crate statistical;1718// Os-specific dependencies19cfg_if! {20 if #[cfg(windows)] {21 extern crate winapi;22 } else {23 extern crate libc;24 }25}2627#[cfg(test)]28#[macro_use]29extern crate approx;301use std::cmp;2use std::env;3use std::error::Error;4use std::io;
4 unmodified lines
9use colored::*;1011mod hyperfine;1243use hyperfine::app::get_arg_matches;44use hyperfine::benchmark::{mean_shell_spawning_time, run_benchmark};45use hyperfine::error::{OptionsError, ParameterScanError};46use hyperfine::export::{ExportManager, ExportType};47use hyperfine::internal::write_benchmark_comparison;48use hyperfine::types::{13use crate::hyperfine::app::get_arg_matches;14use crate::hyperfine::benchmark::{mean_shell_spawning_time, run_benchmark};15use crate::hyperfine::error::{OptionsError, ParameterScanError};16use crate::hyperfine::export::{ExportManager, ExportType};17use crate::hyperfine::internal::write_benchmark_comparison;18use crate::hyperfine::types::{19 BenchmarkResult, CmdFailureAction, Command, HyperfineOptions, OutputStyleOption,20};51use hyperfine::units::Unit;21use crate::hyperfine::units::Unit;2223/// Print error message to stderr and terminate24pub fn error(message: &str) -> ! {25 eprintln!("{} {}", "Error:".red(), message);26 std::process::exit(1);27}2829/// Runs the benchmark for the given commands60fn run(commands: &Vec<Command>, options: &HyperfineOptions) -> io::Result<Vec<BenchmarkResult>> {30fn run(commands: &Vec<Command<'_>>, options: &HyperfineOptions) -> io::Result<Vec<BenchmarkResult>> {31 let shell_spawning_time =32 mean_shell_spawning_time(&options.shell, &options.output_style, options.show_output)?;3334 let mut timing_results = vec![];
52 unmodified lines
87 }88}8990/// Build the HyperfineOptions that correspond to the given ArgMatches121fn build_hyperfine_options(matches: &ArgMatches) -> Result<HyperfineOptions, OptionsError> {91fn build_hyperfine_options(matches: &ArgMatches<'_>) -> Result<HyperfineOptions, OptionsError> {92 let mut options = HyperfineOptions::default();93 let str_to_u64 = |n| u64::from_str_radix(n, 10).ok();9495 options.warmup_count = matches
87 unmodified lines
183}184185/// Build the ExportManager that will export the results specified186/// in the given ArgMatches217fn build_export_manager(matches: &ArgMatches) -> ExportManager {187fn build_export_manager(matches: &ArgMatches<'_>) -> ExportManager {188 let mut export_manager = ExportManager::new();189 {190 let mut add_exporter = |flag, exporttype| {191 if let Some(filename) = matches.value_of(flag) {
8 unmodified lines
200 export_manager201}202203/// Build the commands to benchmark234fn build_commands<'a>(matches: &'a ArgMatches) -> Vec<Command<'a>> {204fn build_commands<'a>(matches: &'a ArgMatches<'_>) -> Vec<Command<'a>> {205 let command_strings = matches.values_of("command").unwrap();206207 let commands = if let Some(args) = matches.values_of("parameter-scan") {208 match parse_parameter_scan_args(args) {
17 unmodified lines
modified:Cargo.lock+3 added-1 removed
151 unmodified lines
152 "csv 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",153 "indicatif 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",154 "libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)",155 "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)",156 "serde_derive 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)",156 "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)",157 "statistical 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",158 "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",159]
300 unmodified lines
460[[package]]461name = "serde"462version = "1.0.91"463source = "registry+https://github.com/rust-lang/crates.io-index"464dependencies = [465 "serde_derive 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)",466]467468[[package]]469name = "serde_derive"470version = "1.0.90"
244 unmodified lines
modified:Cargo.toml+2 added-2 removed
6 unmodified lines
7name = "hyperfine"8readme = "README.md"9repository = "https://github.com/sharkdp/hyperfine"10version = "1.5.0"11edition = "2018"1213[dependencies]14colored = "1.7"15indicatif = "0.11"16statistical = "1.0"17atty = "0.2.2"18cfg-if = "0.1.7"19csv = "1.0.7"19serde = "1.0.91"20serde_derive = "1.0.90"20serde = { version = "1.0.91", features = ["derive"] }21serde_json = "1.0.39"2223[target.'cfg(not(windows))'.dependencies]24libc = "0.2"
11 unmodified lines