Compare commits

...

5 Commits

Author SHA1 Message Date
one230six
c0921351e7 refactor: Optimize code based on cargo clippy suggestions
Signed-off-by: one230six <723682061@qq.com>

refactor: Optimize code based on cargo clippy suggestions

Signed-off-by: one230six <723682061@qq.com>
2024-03-14 08:46:35 +01:00
Everett Pompeii
865b496098 Fix hyperlink sup copy 2024-03-14 08:45:34 +01:00
Serpent7776
51d056a3de Add --sort-by option 2024-03-14 08:26:35 +01:00
Serpent7776
836d1730b5 Fix long labels being cut off 2024-03-14 08:26:35 +01:00
Serpent7776
5c9d7a8b1e Nicer whiskers plot
- add missing encoding when opening input file
- add labels to x ticks, rotated by 45 deg
- sort data by median, ascending
2024-03-14 08:26:35 +01:00
5 changed files with 27 additions and 19 deletions

View File

@ -16,15 +16,14 @@ A special *thank you* goes to our biggest <a href="doc/sponsors.md">sponsor</a>:
<a href="https://bencher.dev/hyperfine/?utm_source=github&utm_medium=referral&utm_campaign=hyperfine&utm_content=wordmark">
<img src="doc/sponsors/bencher_wordmark.svg" width="200" alt="🐰 Bencher">
<br>
<br />
<strong>Continuous Benchmarking: Catch performance regressions in CI</strong>
</a>
<br>
<a href="https://bencher.dev/hyperfine/?utm_source=github&utm_medium=referral&utm_campaign=hyperfine&utm_content=copy">
<sub>Track the results of your <code>hyperfine</code> benchmarks over time with Bencher.</sub>
<br>
<sup>Detect and prevent performance regressions before they make it to production.</sup>
</a>
<br />
<br />
Track the results of your <code>hyperfine</code> benchmarks over time with Bencher. \
Detect and prevent performance regressions before they make it to production.
## Features

View File

@ -15,6 +15,7 @@ import matplotlib.pyplot as plt
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("file", help="JSON file with benchmark results")
parser.add_argument("--title", help="Plot Title")
parser.add_argument("--sort-by", choices=['median'], help="Sort method")
parser.add_argument(
"--labels", help="Comma-separated list of entries for the plot legend"
)
@ -24,7 +25,7 @@ parser.add_argument(
args = parser.parse_args()
with open(args.file) as f:
with open(args.file, encoding='utf-8') as f:
results = json.load(f)["results"]
if args.labels:
@ -33,6 +34,13 @@ else:
labels = [b["command"] for b in results]
times = [b["times"] for b in results]
if args.sort_by == 'median':
medians = [b["median"] for b in results]
indices = sorted(range(len(labels)), key=lambda k: medians[k])
labels = [labels[i] for i in indices]
times = [times[i] for i in indices]
plt.figure(figsize=(10, 6), constrained_layout=True)
boxplot = plt.boxplot(times, vert=True, patch_artist=True)
cmap = plt.get_cmap("rainbow")
colors = [cmap(val / len(times)) for val in range(len(times))]
@ -45,6 +53,7 @@ if args.title:
plt.legend(handles=boxplot["boxes"], labels=labels, loc="best", fontsize="medium")
plt.ylabel("Time [s]")
plt.ylim(0, None)
plt.xticks(list(range(1, len(labels)+1)), labels, rotation=45)
if args.output:
plt.savefig(args.output)
else:

View File

@ -59,11 +59,11 @@ impl<'a> Command<'a> {
}
pub fn get_name_with_unused_parameters(&self) -> String {
let parameters =
self.get_unused_parameters()
.fold(String::new(), |output, (parameter, value)| {
output + &format!("{} = {}, ", parameter, value.to_string())
});
let parameters = self
.get_unused_parameters()
.fold(String::new(), |output, (parameter, value)| {
output + &format!("{} = {}, ", parameter, value)
});
let parameters = parameters.trim_end_matches(", ");
let parameters = if parameters.is_empty() {
"".into()

View File

@ -1,4 +1,5 @@
use crate::util::number::Number;
use std::fmt::Display;
pub mod range_step;
pub mod tokenize;
@ -9,12 +10,13 @@ pub enum ParameterValue {
Numeric(Number),
}
impl ToString for ParameterValue {
fn to_string(&self) -> String {
match self {
impl Display for ParameterValue {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let str = match self {
ParameterValue::Text(ref value) => value.clone(),
ParameterValue::Numeric(value) => value.to_string(),
}
};
write!(f, "{}", str)
}
}

View File

@ -1,5 +1,3 @@
use std::iter::Iterator;
/// A max function for f64's without NaNs
pub fn max(vals: &[f64]) -> f64 {
*vals