Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

addition of fn print_newline to stop same line behaviour when using c… #564

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 20 additions & 20 deletions src/report.rs
@@ -1,20 +1,17 @@
use crate::stats::univariate::outliers::tukey::LabeledSample;
use crate::{csv_report::FileCsvReport, stats::bivariate::regression::Slope};
use crate::{html::Html, stats::bivariate::Data};

use crate::estimate::{ChangeDistributions, ChangeEstimates, Distributions, Estimate, Estimates};
use crate::format;
use crate::measurement::ValueFormatter;
use crate::stats::univariate::outliers::tukey::LabeledSample;
use crate::stats::univariate::Sample;
use crate::stats::Distribution;
use crate::{csv_report::FileCsvReport, stats::bivariate::regression::Slope};
use crate::{html::Html, stats::bivariate::Data};
use crate::{PlotConfiguration, Throughput};
use std::cell::Cell;
use std::cmp;
use std::collections::HashSet;
use std::fmt;
use std::io::stdout;
use std::io::Write;
use std::io::{stdout, Write};
use std::path::{Path, PathBuf};
use std::{cmp, fmt};

const MAX_DIRECTORY_NAME_LEN: usize = 64;
const MAX_TITLE_LEN: usize = 100;
Expand Down Expand Up @@ -386,7 +383,7 @@ impl CliReport {
}

fn text_overwrite(&self) {
if self.enable_text_overwrite {
if self.enable_text_overwrite && self.last_line_len.get() > 0 {
print!("\r");
for _ in 0..self.last_line_len.get() {
print!(" ");
Expand All @@ -399,6 +396,7 @@ impl CliReport {
#[cfg_attr(feature = "cargo-clippy", allow(clippy::needless_pass_by_value))]
fn print_overwritable(&self, s: String) {
if self.enable_text_overwrite {
self.text_overwrite();
self.last_line_len.set(s.len());
print!("{}", s);
stdout().flush().unwrap();
Expand All @@ -407,6 +405,16 @@ impl CliReport {
}
}

#[cfg_attr(feature = "cargo-clippy", allow(clippy::needless_pass_by_value))]
fn print_newline(&self, s: String) {
if self.last_line_len.get() > 0 {
self.text_overwrite();
self.last_line_len.set(0);
println!();
}
println!("{}", s);
}

fn green(&self, s: String) -> String {
if self.enable_text_coloring {
format!("\x1B[32m{}\x1B[39m", s)
Expand Down Expand Up @@ -493,7 +501,6 @@ impl Report for CliReport {
}

fn profile(&self, id: &BenchmarkId, _: &ReportContext, warmup_ns: f64) {
self.text_overwrite();
self.print_overwritable(format!(
"Benchmarking {}: Profiling for {}",
id,
Expand All @@ -502,7 +509,6 @@ impl Report for CliReport {
}

fn warmup(&self, id: &BenchmarkId, _: &ReportContext, warmup_ns: f64) {
self.text_overwrite();
self.print_overwritable(format!(
"Benchmarking {}: Warming up for {}",
id,
Expand All @@ -511,12 +517,10 @@ impl Report for CliReport {
}

fn terminated(&self, id: &BenchmarkId, _: &ReportContext) {
self.text_overwrite();
println!("Benchmarking {}: Complete (Analysis Disabled)", id);
self.print_newline(format!("Benchmarking {}: Complete (Analysis Disabled)", id));
}

fn analysis(&self, id: &BenchmarkId, _: &ReportContext) {
self.text_overwrite();
self.print_overwritable(format!("Benchmarking {}: Analyzing", id));
}

Expand All @@ -528,7 +532,6 @@ impl Report for CliReport {
estimate_ns: f64,
iter_count: u64,
) {
self.text_overwrite();
let iter_string = if self.verbose {
format!("{} iterations", iter_count)
} else {
Expand All @@ -551,10 +554,7 @@ impl Report for CliReport {
meas: &MeasurementData<'_>,
formatter: &dyn ValueFormatter,
) {
self.text_overwrite();

let typical_estimate = &meas.absolute_estimates.typical();

{
let mut id = id.as_title().to_owned();

Expand All @@ -564,7 +564,7 @@ impl Report for CliReport {
}
let id_len = id.len();

println!(
self.print_newline(format!(
"{}{}time: [{} {} {}]",
self.green(id),
" ".repeat(24 - id_len),
Expand All @@ -575,7 +575,7 @@ impl Report for CliReport {
self.faint(
formatter.format_value(typical_estimate.confidence_interval.upper_bound)
)
);
));
}

if let Some(ref throughput) = meas.throughput {
Expand Down