Skip to content
Myr

Move progress bar to separate module

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

authored by David Peter · committed by David Peter · parent 8618c86 · Browse files · 4 files+32 added−29 removed
This commit

State

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

Diff stats

4 files+32 added−29 removed

  • other:+32 added−29 removed

4 files+32 added−29 removed

modified:src/benchmark.rs+2 added-1 removed
6 unmodified lines
78use crate::benchmark_result::BenchmarkResult;9use crate::command::Command;10use crate::format::{format_duration, format_duration_unit};11use crate::internal::{get_progress_bar, max, min, MIN_EXECUTION_TIME};11use crate::internal::{max, min, MIN_EXECUTION_TIME};12use crate::progress_bar::get_progress_bar;13use crate::options::{CmdFailureAction, HyperfineOptions, OutputStyleOption};14use crate::outlier_detection::{modified_zscores, OUTLIER_THRESHOLD};15use crate::shell::execute_and_time;16use crate::timer::wallclocktimer::WallClockTimer;
469 unmodified lines
modified:src/internal.rs-28 removed
1use std::cmp::Ordering;2use std::iter::Iterator;34use colored::*;5use indicatif::{ProgressBar, ProgressStyle};56use crate::benchmark_result::BenchmarkResult;8use crate::options::OutputStyleOption;7use crate::units::{Scalar, Second};89/// Threshold for warning about fast execution time10pub const MIN_EXECUTION_TIME: Second = 5e-3;1114#[cfg(not(windows))]15const TICK_SETTINGS: (&str, u64) = ("⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏ ", 80);1617#[cfg(windows)]18const TICK_SETTINGS: (&str, u64) = (r"+-x| ", 200);1920/// Return a pre-configured progress bar21pub fn get_progress_bar(length: u64, msg: &str, option: OutputStyleOption) -> ProgressBar {22 let progressbar_style = match option {23 OutputStyleOption::Basic | OutputStyleOption::Color => ProgressStyle::default_bar(),24 _ => ProgressStyle::default_spinner()25 .tick_chars(TICK_SETTINGS.0)26 .template(" {spinner} {msg:<30} {wide_bar} ETA {eta_precise}"),27 };2829 let progress_bar = match option {30 OutputStyleOption::Basic | OutputStyleOption::Color => ProgressBar::hidden(),31 _ => ProgressBar::new(length),32 };33 progress_bar.set_style(progressbar_style);34 progress_bar.enable_steady_tick(TICK_SETTINGS.1);35 progress_bar.set_message(msg.to_owned());3637 progress_bar38}3912/// A max function for f64's without NaNs13pub fn max(vals: &[f64]) -> f64 {14 *vals15 .iter()
212 unmodified lines
modified:src/main.rs+1 added
16 unmodified lines
17pub mod internal;18pub mod options;19pub mod outlier_detection;20pub mod parameter_range;21pub mod progress_bar;22pub mod shell;23pub mod timer;24pub mod types;25pub mod units;
398 unmodified lines
added:src/progress_bar.rs+29 added
1use indicatif::{ProgressBar, ProgressStyle};23use crate::options::OutputStyleOption;45#[cfg(not(windows))]6const TICK_SETTINGS: (&str, u64) = ("⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏ ", 80);78#[cfg(windows)]9const TICK_SETTINGS: (&str, u64) = (r"+-x| ", 200);1011/// Return a pre-configured progress bar12pub fn get_progress_bar(length: u64, msg: &str, option: OutputStyleOption) -> ProgressBar {13 let progressbar_style = match option {14 OutputStyleOption::Basic | OutputStyleOption::Color => ProgressStyle::default_bar(),15 _ => ProgressStyle::default_spinner()16 .tick_chars(TICK_SETTINGS.0)17 .template(" {spinner} {msg:<30} {wide_bar} ETA {eta_precise}"),18 };1920 let progress_bar = match option {21 OutputStyleOption::Basic | OutputStyleOption::Color => ProgressBar::hidden(),22 _ => ProgressBar::new(length),23 };24 progress_bar.set_style(progressbar_style);25 progress_bar.enable_steady_tick(TICK_SETTINGS.1);26 progress_bar.set_message(msg.to_owned());2728 progress_bar29}