Compare commits

...

5 Commits

Author SHA1 Message Date
Jooris Hadeler
98b71370fc
Merge 02975df2ad into ef9e1409c6 2024-07-21 19:05:40 +02:00
Spreadcat
ef9e1409c6
add: legend modification parameters and output DPI (#758)
* add: legend modification parameters and output DPI

This commit adds a CLI parameter to plot_histogram in order to position
the legend of the plot on the diagram.
It also defines the output DPI for the plot to 600 dpi.

Plot_progression gets a CLI paramter to add a custom label and to
overwrite the default one.

---------

Co-authored-by: dbv <jt@dbv03.linpro.no>
Co-authored-by: dbv <spreadcat.github@micronarrativ.org>
2024-07-17 20:40:12 +02:00
Jooris Hadeler
02975df2ad Move -E, --show-elapsed flag to a more sensible position. 2023-11-20 19:40:04 +01:00
Jooris Hadeler
c83b4126ea Reset elapsed every time the progress bar is increased. 2023-11-20 19:39:31 +01:00
Jooris Hadeler
4e8cb3fec0 Add a --show-elapsed flag to optionally enable a the elapsed time counter. 2023-11-20 18:49:44 +01:00
6 changed files with 56 additions and 8 deletions

View File

@ -6,6 +6,7 @@ import argparse
import json
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.font_manager
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("file", help="JSON file with benchmark results")
@ -14,6 +15,11 @@ parser.add_argument(
"--labels", help="Comma-separated list of entries for the plot legend"
)
parser.add_argument("--bins", help="Number of bins (default: auto)")
parser.add_argument(
"--legend-location", help="Location of the legend on plot (default: upper center)",
choices=["upper center", "lower center", "right", "left", "best", "upper left", "upper right", "lower left", "lower right", "center left", "center right", "center"],
default="upper center"
)
parser.add_argument(
"--type", help="Type of histogram (*bar*, barstacked, step, stepfilled)"
)
@ -47,6 +53,7 @@ t_max = float(args.t_max) if args.t_max else np.max(list(map(np.max, all_times))
bins = int(args.bins) if args.bins else "auto"
histtype = args.type if args.type else "bar"
plt.figure(figsize=(10, 5))
plt.hist(
all_times,
label=labels,
@ -54,7 +61,12 @@ plt.hist(
histtype=histtype,
range=(t_min, t_max),
)
plt.legend(prop={"family": ["Source Code Pro", "Fira Mono", "Courier New"]})
plt.legend(
loc=args.legend_location,
fancybox=True,
shadow=True,
prop={"size": 7, "family": ["Source Code Pro", "Fira Mono", "Courier New"]}
)
plt.xlabel("Time [s]")
if args.title:
@ -66,6 +78,6 @@ else:
plt.ylim(0, None)
if args.output:
plt.savefig(args.output)
plt.savefig(args.output, dpi=600)
else:
plt.show()

View File

@ -180,6 +180,7 @@ impl<'a> Executor for ShellExecutor<'a> {
COUNT,
"Measuring shell spawning time",
self.options.output_style,
self.options.show_elapsed,
))
} else {
None
@ -214,7 +215,8 @@ impl<'a> Executor for ShellExecutor<'a> {
}
if let Some(bar) = progress_bar.as_ref() {
bar.inc(1)
bar.inc(1);
bar.reset_elapsed();
}
}

View File

@ -182,6 +182,7 @@ impl<'a> Benchmark<'a> {
self.options.warmup_count,
"Performing warmup runs",
self.options.output_style,
self.options.show_elapsed,
))
} else {
None
@ -192,7 +193,8 @@ impl<'a> Benchmark<'a> {
let _ = self.executor.run_command_and_measure(self.command, None)?;
let _ = run_conclusion_command()?;
if let Some(bar) = progress_bar.as_ref() {
bar.inc(1)
bar.inc(1);
bar.reset_elapsed();
}
}
if let Some(bar) = progress_bar.as_ref() {
@ -206,6 +208,7 @@ impl<'a> Benchmark<'a> {
self.options.run_bounds.min,
"Initial time measurement",
self.options.output_style,
self.options.show_elapsed,
))
} else {
None
@ -256,7 +259,8 @@ impl<'a> Benchmark<'a> {
bar.set_length(count)
}
if let Some(bar) = progress_bar.as_ref() {
bar.inc(1)
bar.inc(1);
bar.reset_elapsed();
}
// Gather statistics (perform the actual benchmark)
@ -283,7 +287,8 @@ impl<'a> Benchmark<'a> {
all_succeeded = all_succeeded && success;
if let Some(bar) = progress_bar.as_ref() {
bar.inc(1)
bar.inc(1);
bar.reset_elapsed();
}
run_conclusion_command()?;

View File

@ -254,6 +254,17 @@ fn build_command() -> Command {
* 'mean-time': order benchmarks by mean runtime\n"
),
)
.arg(
Arg::new("show-elapsed")
.long("show-elapsed")
.short('E')
.action(ArgAction::SetTrue)
.help(
"Show time elapsed since the current run was started. \
This is useful for especially long benchmarks to see \
the progress the benchmark has made"
)
)
.arg(
Arg::new("time-unit")
.long("time-unit")

View File

@ -239,6 +239,9 @@ pub struct Options {
/// Which time unit to use when displaying results
pub time_unit: Option<Unit>,
/// Show elapsed time since current run start.
pub show_elapsed: bool,
}
impl Default for Options {
@ -260,6 +263,7 @@ impl Default for Options {
command_output_policy: CommandOutputPolicy::Null,
time_unit: None,
command_input_policy: CommandInputPolicy::Null,
show_elapsed: false,
}
}
}
@ -433,6 +437,10 @@ impl Options {
CommandInputPolicy::Null
};
if matches.get_flag("show-elapsed") {
options.show_elapsed = true;
}
Ok(options)
}

View File

@ -10,12 +10,22 @@ const TICK_SETTINGS: (&str, u64) = ("⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏ ", 80);
const TICK_SETTINGS: (&str, u64) = (r"+-x| ", 200);
/// Return a pre-configured progress bar
pub fn get_progress_bar(length: u64, msg: &str, option: OutputStyleOption) -> ProgressBar {
pub fn get_progress_bar(
length: u64,
msg: &str,
option: OutputStyleOption,
show_elapsed: bool,
) -> ProgressBar {
let template_str = match show_elapsed {
true => " {spinner} {msg:<30} {wide_bar} ET {elapsed_precise} ETA {eta_precise} ",
false => " {spinner} {msg:<30} {wide_bar} ETA {eta_precise} ",
};
let progressbar_style = match option {
OutputStyleOption::Basic | OutputStyleOption::Color => ProgressStyle::default_bar(),
_ => ProgressStyle::default_spinner()
.tick_chars(TICK_SETTINGS.0)
.template(" {spinner} {msg:<30} {wide_bar} ETA {eta_precise} ")
.template(template_str)
.expect("no template error"),
};