Compare commits

...

24 Commits

Author SHA1 Message Date
David Peter
171356267d
Merge 34cd5b9bb5 into df34f32dca 2024-07-04 15:44:35 +02:00
dependabot[bot]
df34f32dca Bump once_cell from 1.18.0 to 1.19.0
Bumps [once_cell](https://github.com/matklad/once_cell) from 1.18.0 to 1.19.0.
- [Changelog](https://github.com/matklad/once_cell/blob/master/CHANGELOG.md)
- [Commits](https://github.com/matklad/once_cell/compare/v1.18.0...v1.19.0)

---
updated-dependencies:
- dependency-name: once_cell
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-07-01 13:22:08 +02:00
dependabot[bot]
4c3f6ad4f8 Bump rust_decimal from 1.32.0 to 1.35.0
Bumps [rust_decimal](https://github.com/paupino/rust-decimal) from 1.32.0 to 1.35.0.
- [Release notes](https://github.com/paupino/rust-decimal/releases)
- [Changelog](https://github.com/paupino/rust-decimal/blob/master/CHANGELOG.md)
- [Commits](https://github.com/paupino/rust-decimal/compare/1.32.0...1.35.0)

---
updated-dependencies:
- dependency-name: rust_decimal
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-07-01 13:17:38 +02:00
Jan-Eric Nitschke
13547e973c Change message for identical time and add test for it 2024-06-30 22:45:40 +02:00
Jan-Eric Nitschke
9134337b62 Fix typo 2024-06-30 22:45:40 +02:00
Jan-Eric Nitschke
d4749b015f Fix prepare and conclude behaviour and add tests. 2024-06-30 22:45:40 +02:00
Jan-Eric Nitschke
9806ed7694 Added option to manually specify a reference to compare the results to. 2024-06-30 22:45:40 +02:00
Bryan Honof
4a00f1821c docs: Add flox install 2024-06-22 22:42:33 +02:00
Hamir Mahal
981db9d102 fix: formatting in src/command.rs 2024-06-01 11:07:23 +02:00
Hamir Mahal
ef1263279d style: simplify string interpolation 2024-06-01 11:07:23 +02:00
dependabot[bot]
e8ff88dad1 Bump colored from 2.0.4 to 2.1.0
Bumps [colored](https://github.com/mackwic/colored) from 2.0.4 to 2.1.0.
- [Release notes](https://github.com/mackwic/colored/releases)
- [Changelog](https://github.com/colored-rs/colored/blob/master/CHANGELOG.md)
- [Commits](https://github.com/mackwic/colored/compare/v2.0.4...v2.1.0)

---
updated-dependencies:
- dependency-name: colored
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-04-07 20:06:41 +02:00
Aymen
c6a6dccd95 Fix the Arch url to repo in README.md 2024-04-07 20:00:06 +02:00
David Legrand
d712879c9f docs: add Exherbo Linux in README.md setup instructions 2024-04-07 19:59:41 +02:00
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
dependabot[bot]
5493cf5039 Bump softprops/action-gh-release from 1 to 2
Bumps [softprops/action-gh-release](https://github.com/softprops/action-gh-release) from 1 to 2.
- [Release notes](https://github.com/softprops/action-gh-release/releases)
- [Changelog](https://github.com/softprops/action-gh-release/blob/master/CHANGELOG.md)
- [Commits](https://github.com/softprops/action-gh-release/compare/v1...v2)

---
updated-dependencies:
- dependency-name: softprops/action-gh-release
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-03-12 21:33:20 +01:00
Hamir Mahal
6c774103d9 refactor: replace repeated string allocation
on each iteration with one `String` creation in
`fold`, for efficiency
2024-03-12 21:32:40 +01:00
Everett Pompeii
09c39d8989 Add Bencher as sponsor 2024-03-12 19:53:24 +01:00
Hamir Mahal
96f8ae52ad refactor: remove redundant redefinition 2024-03-10 21:02:09 +01:00
dependabot[bot]
ce6df59f0f Bump anyhow from 1.0.75 to 1.0.80
Bumps [anyhow](https://github.com/dtolnay/anyhow) from 1.0.75 to 1.0.80.
- [Release notes](https://github.com/dtolnay/anyhow/releases)
- [Commits](https://github.com/dtolnay/anyhow/compare/1.0.75...1.0.80)

---
updated-dependencies:
- dependency-name: anyhow
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-03-09 22:43:23 +01:00
Casper Lindschouw
39df4d821d Build binaries for aarch64-apple-darwin 2024-03-09 22:43:04 +01:00
25 changed files with 694 additions and 160 deletions

View File

@ -71,6 +71,7 @@ jobs:
matrix:
job:
- { target: aarch64-unknown-linux-gnu , os: ubuntu-20.04, use-cross: true }
- { target: aarch64-apple-darwin , os: macos-14 }
- { target: arm-unknown-linux-gnueabihf , os: ubuntu-20.04, use-cross: true }
- { target: arm-unknown-linux-musleabihf, os: ubuntu-20.04, use-cross: true }
- { target: i686-pc-windows-msvc , os: windows-2019 }
@ -325,7 +326,7 @@ jobs:
echo "IS_RELEASE=${IS_RELEASE}" >> $GITHUB_OUTPUT
- name: Publish archives and packages
uses: softprops/action-gh-release@v1
uses: softprops/action-gh-release@v2
if: steps.is-release.outputs.IS_RELEASE
with:
files: |

179
Cargo.lock generated
View File

@ -13,17 +13,6 @@ dependencies = [
"version_check",
]
[[package]]
name = "ahash"
version = "0.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2c99f64d1e06488f620f932677e24bc6e2897582980441ae90a671415bd7ec2f"
dependencies = [
"cfg-if",
"once_cell",
"version_check",
]
[[package]]
name = "aho-corasick"
version = "1.1.1"
@ -83,9 +72,9 @@ dependencies = [
[[package]]
name = "anyhow"
version = "1.0.75"
version = "1.0.80"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6"
checksum = "5ad32ce52e4161730f7098c077cd2ed6229b5804ccf99e5366be1ab72a98b4e1"
[[package]]
name = "approx"
@ -158,47 +147,26 @@ dependencies = [
[[package]]
name = "borsh"
version = "0.10.3"
version = "1.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4114279215a005bc675e386011e594e1d9b800918cea18fcadadcce864a2046b"
checksum = "a6362ed55def622cddc70a4746a68554d7b687713770de539e59a739b249f8ed"
dependencies = [
"borsh-derive",
"hashbrown 0.13.2",
"cfg_aliases",
]
[[package]]
name = "borsh-derive"
version = "0.10.3"
version = "1.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0754613691538d51f329cce9af41d7b7ca150bc973056f1156611489475f54f7"
checksum = "c3ef8005764f53cd4dca619f5bf64cafd4664dada50ece25e4d81de54c80cc0b"
dependencies = [
"borsh-derive-internal",
"borsh-schema-derive-internal",
"once_cell",
"proc-macro-crate",
"proc-macro2",
"syn 1.0.109",
]
[[package]]
name = "borsh-derive-internal"
version = "0.10.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "afb438156919598d2c7bad7e1c0adf3d26ed3840dbc010db1a882a65583ca2fb"
dependencies = [
"proc-macro2",
"quote",
"syn 1.0.109",
]
[[package]]
name = "borsh-schema-derive-internal"
version = "0.10.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "634205cc43f74a1b9046ef87c4540ebda95696ec0f315024860cad7c5b0f5ccd"
dependencies = [
"proc-macro2",
"quote",
"syn 1.0.109",
"syn 2.0.37",
"syn_derive",
]
[[package]]
@ -246,6 +214,12 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "cfg_aliases"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724"
[[package]]
name = "clap"
version = "4.4.12"
@ -300,11 +274,10 @@ checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7"
[[package]]
name = "colored"
version = "2.0.4"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2674ec482fbc38012cf31e6c42ba0177b431a0cb6f15fe40efa5aab1bda516f6"
checksum = "cbf2150cce219b664a8a70df7a1f933836724b503f8a413af9365b4dcc4d90b8"
dependencies = [
"is-terminal",
"lazy_static",
"windows-sys 0.48.0",
]
@ -367,6 +340,12 @@ version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f"
[[package]]
name = "equivalent"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
[[package]]
name = "errno"
version = "0.3.8"
@ -421,23 +400,14 @@ version = "0.12.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888"
dependencies = [
"ahash 0.7.6",
"ahash",
]
[[package]]
name = "hashbrown"
version = "0.13.2"
version = "0.14.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e"
dependencies = [
"ahash 0.8.3",
]
[[package]]
name = "hermit-abi"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7"
checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1"
[[package]]
name = "hyperfine"
@ -466,6 +436,16 @@ dependencies = [
"windows-sys 0.48.0",
]
[[package]]
name = "indexmap"
version = "2.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26"
dependencies = [
"equivalent",
"hashbrown 0.14.5",
]
[[package]]
name = "indicatif"
version = "0.17.4"
@ -488,17 +468,6 @@ dependencies = [
"cfg-if",
]
[[package]]
name = "is-terminal"
version = "0.4.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b"
dependencies = [
"hermit-abi",
"rustix",
"windows-sys 0.48.0",
]
[[package]]
name = "itertools"
version = "0.11.0"
@ -640,9 +609,9 @@ checksum = "830b246a0e5f20af87141b25c173cd1b609bd7779a4617d6ec582abaf90870f3"
[[package]]
name = "once_cell"
version = "1.18.0"
version = "1.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d"
checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92"
[[package]]
name = "portable-atomic"
@ -689,11 +658,34 @@ dependencies = [
[[package]]
name = "proc-macro-crate"
version = "0.1.5"
version = "3.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d6ea3c4595b96363c13943497db34af4460fb474a95c43f4446ad341b8c9785"
checksum = "6d37c51ca738a55da99dc0c4a34860fd675453b8b36209178c2249bb13651284"
dependencies = [
"toml",
"toml_edit",
]
[[package]]
name = "proc-macro-error"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
dependencies = [
"proc-macro-error-attr",
"proc-macro2",
"quote",
"version_check",
]
[[package]]
name = "proc-macro-error-attr"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
dependencies = [
"proc-macro2",
"quote",
"version_check",
]
[[package]]
@ -962,9 +954,9 @@ dependencies = [
[[package]]
name = "rust_decimal"
version = "1.32.0"
version = "1.35.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4c4216490d5a413bc6d10fa4742bd7d4955941d062c0ef873141d6b0e7b30fd"
checksum = "1790d1c4c0ca81211399e0e0af16333276f375209e71a37b67698a373db5b47a"
dependencies = [
"arrayvec",
"borsh",
@ -1082,6 +1074,18 @@ dependencies = [
"unicode-ident",
]
[[package]]
name = "syn_derive"
version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1329189c02ff984e9736652b1631330da25eaa6bc639089ed4915d25446cbe7b"
dependencies = [
"proc-macro-error",
"proc-macro2",
"quote",
"syn 2.0.37",
]
[[package]]
name = "tap"
version = "1.0.1"
@ -1153,12 +1157,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
[[package]]
name = "toml"
version = "0.5.11"
name = "toml_datetime"
version = "0.6.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234"
checksum = "4badfd56924ae69bcc9039335b2e017639ce3f9b001c393c1b2d1ef846ce2cbf"
[[package]]
name = "toml_edit"
version = "0.21.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a8534fd7f78b5405e860340ad6575217ce99f38d4d5c8f2442cb5ecb50090e1"
dependencies = [
"serde",
"indexmap",
"toml_datetime",
"winnow",
]
[[package]]
@ -1426,6 +1438,15 @@ version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04"
[[package]]
name = "winnow"
version = "0.5.40"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f593a95398737aeed53e489c785df13f3618e41dbcd6718c6addbf1395aa6876"
dependencies = [
"memchr",
]
[[package]]
name = "wyz"
version = "0.5.1"

View File

@ -17,13 +17,13 @@ rust-version = "1.70.0"
windows_process_extensions_main_thread_handle = []
[dependencies]
colored = "2.0"
colored = "2.1"
indicatif = "=0.17.4"
statistical = "1.0"
csv = "1.1"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
rust_decimal = "1.31"
rust_decimal = "1.35"
rand = "0.8"
shell-words = "1.0"
thiserror = "1.0"
@ -42,7 +42,7 @@ windows-sys = { version = "0.48", features = [
] }
[target.'cfg(all(windows, not(windows_process_extensions_main_thread_handle)))'.dependencies]
once_cell = "1.17"
once_cell = "1.19"
[target.'cfg(target_os="linux")'.dependencies]
nix = { version = "0.27.1", features = ["zerocopy"] }

View File

@ -10,6 +10,21 @@ A command-line benchmarking tool.
![hyperfine](https://i.imgur.com/z19OYxE.gif)
## Sponsors
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 />
<strong>Continuous Benchmarking: Catch performance regressions in CI</strong>
</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
* Statistical analysis across multiple runs.
@ -191,7 +206,7 @@ apk add hyperfine
### On Arch Linux
On Arch Linux, hyperfine can be installed [from the official repositories](https://www.archlinux.org/packages/community/x86_64/hyperfine/):
On Arch Linux, hyperfine can be installed [from the official repositories](https://archlinux.org/packages/extra/x86_64/hyperfine/):
```
pacman -S hyperfine
```
@ -203,6 +218,14 @@ On Debian Linux, hyperfine can be installed [from the testing repositories](http
apt install hyperfine
```
### On Exherbo Linux
On Exherbo Linux, hyperfine can be installed [from the rust repositories]([https://packages.debian.org/testing/main/hyperfine](https://gitlab.exherbo.org/exherbo/rust/-/tree/master/packages/sys-apps/hyperfine)
```
cave resolve -x repository/rust
cave resolve -x hyperfine
```
### On Funtoo Linux
On Funtoo Linux, hyperfine can be installed [from core-kit](https://github.com/funtoo/core-kit/tree/1.4-release/app-benchmarks/hyperfine):
@ -217,6 +240,14 @@ On NixOS, hyperfine can be installed [from the official repositories](https://ni
nix-env -i hyperfine
```
### On Flox
On Flox, hyperfine can be installed as follows.
```
flox install hyperfine
```
Hyperfine's version in Flox follows that of Nix.
### On openSUSE
On openSUSE, hyperfine can be installed [from the official repositories](https://software.opensuse.org/package/hyperfine):

12
doc/sponsors.md Normal file
View File

@ -0,0 +1,12 @@
## Sponsors
`hyperfine` development is sponsored by many individuals and companies. Thank you very much!
Please note, that being sponsored does not affect the individuality of the `hyperfine`
project or affect the maintainers' actions in any way.
We remain impartial and continue to assess pull requests solely on merit - the
features added, bugs solved, and effect on the overall complexity of the code.
No issue will have a different priority based on sponsorship status of the
reporter.
If you want to see our biggest sponsors, check the top of [`README.md`](../README.md#sponsors).

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 24 KiB

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

@ -54,7 +54,7 @@ fn run_command_and_measure_common(
);
let result = execute_and_measure(command)
.with_context(|| format!("Failed to run command '{}'", command_name))?;
.with_context(|| format!("Failed to run command '{command_name}'"))?;
if command_failure_action == CmdFailureAction::RaiseError && !result.status.success() {
bail!(
@ -62,7 +62,7 @@ fn run_command_and_measure_common(
Alternatively, use the '--show-output' option to debug what went wrong.",
result.status.code().map_or(
"The process has been terminated by a signal".into(),
|c| format!("Command terminated with non-zero exit code: {}", c)
|c| format!("Command terminated with non-zero exit code: {c}")
)
);
}

View File

@ -312,7 +312,7 @@ impl<'a> Benchmark<'a> {
let (mean_str, time_unit) = format_duration_unit(t_mean, self.options.time_unit);
let min_str = format_duration(t_min, Some(time_unit));
let max_str = format_duration(t_max, Some(time_unit));
let num_str = format!("{} runs", t_num);
let num_str = format!("{t_num} runs");
let user_str = format_duration(user_mean, Some(time_unit));
let system_str = format_duration(system_mean, Some(time_unit));

View File

@ -8,14 +8,16 @@ pub struct BenchmarkResultWithRelativeSpeed<'a> {
pub result: &'a BenchmarkResult,
pub relative_speed: Scalar,
pub relative_speed_stddev: Option<Scalar>,
pub is_fastest: bool,
pub is_reference: bool,
// Less means faster
pub relative_ordering: Ordering,
}
pub fn compare_mean_time(l: &BenchmarkResult, r: &BenchmarkResult) -> Ordering {
l.mean.partial_cmp(&r.mean).unwrap_or(Ordering::Equal)
}
fn fastest_of(results: &[BenchmarkResult]) -> &BenchmarkResult {
pub fn fastest_of(results: &[BenchmarkResult]) -> &BenchmarkResult {
results
.iter()
.min_by(|&l, &r| compare_mean_time(l, r))
@ -24,32 +26,38 @@ fn fastest_of(results: &[BenchmarkResult]) -> &BenchmarkResult {
fn compute_relative_speeds<'a>(
results: &'a [BenchmarkResult],
fastest: &'a BenchmarkResult,
reference: &'a BenchmarkResult,
sort_order: SortOrder,
) -> Vec<BenchmarkResultWithRelativeSpeed<'a>> {
let mut results: Vec<_> = results
.iter()
.map(|result| {
let is_fastest = result == fastest;
let is_reference = result == reference;
let relative_ordering = compare_mean_time(result, reference);
if result.mean == 0.0 {
return BenchmarkResultWithRelativeSpeed {
result,
relative_speed: if is_fastest { 1.0 } else { f64::INFINITY },
relative_speed: if is_reference { 1.0 } else { f64::INFINITY },
relative_speed_stddev: None,
is_fastest,
is_reference,
relative_ordering,
};
}
let ratio = result.mean / fastest.mean;
let ratio = match relative_ordering {
Ordering::Less => reference.mean / result.mean,
Ordering::Equal => 1.0,
Ordering::Greater => result.mean / reference.mean,
};
// https://en.wikipedia.org/wiki/Propagation_of_uncertainty#Example_formulas
// Covariance asssumed to be 0, i.e. variables are assumed to be independent
let ratio_stddev = match (result.stddev, fastest.stddev) {
let ratio_stddev = match (result.stddev, reference.stddev) {
(Some(result_stddev), Some(fastest_stddev)) => Some(
ratio
* ((result_stddev / result.mean).powi(2)
+ (fastest_stddev / fastest.mean).powi(2))
+ (fastest_stddev / reference.mean).powi(2))
.sqrt(),
),
_ => None,
@ -59,7 +67,8 @@ fn compute_relative_speeds<'a>(
result,
relative_speed: ratio,
relative_speed_stddev: ratio_stddev,
is_fastest,
is_reference,
relative_ordering,
}
})
.collect();
@ -74,6 +83,18 @@ fn compute_relative_speeds<'a>(
results
}
pub fn compute_with_check_from_reference<'a>(
results: &'a [BenchmarkResult],
reference: &'a BenchmarkResult,
sort_order: SortOrder,
) -> Option<Vec<BenchmarkResultWithRelativeSpeed<'a>>> {
if fastest_of(results).mean == 0.0 || reference.mean == 0.0 {
return None;
}
Some(compute_relative_speeds(results, reference, sort_order))
}
pub fn compute_with_check(
results: &[BenchmarkResult],
sort_order: SortOrder,
@ -134,6 +155,20 @@ fn test_compute_relative_speed() {
assert_relative_eq!(2.5, annotated_results[2].relative_speed);
}
#[test]
fn test_compute_relative_speed_with_reference() {
use approx::assert_relative_eq;
let results = vec![create_result("cmd2", 2.0), create_result("cmd3", 5.0)];
let reference = create_result("cmd2", 4.0);
let annotated_results =
compute_with_check_from_reference(&results, &reference, SortOrder::Command).unwrap();
assert_relative_eq!(2.0, annotated_results[0].relative_speed);
assert_relative_eq!(1.25, annotated_results[1].relative_speed);
}
#[test]
fn test_compute_relative_speed_for_zero_times() {
let results = vec![create_result("cmd1", 1.0), create_result("cmd2", 0.0)];

View File

@ -1,10 +1,10 @@
use colored::*;
use super::benchmark_result::BenchmarkResult;
use super::executor::{Executor, MockExecutor, RawExecutor, ShellExecutor};
use super::{relative_speed, Benchmark};
use colored::*;
use std::cmp::Ordering;
use crate::command::Commands;
use crate::command::{Command, Commands};
use crate::export::ExportManager;
use crate::options::{ExecutorKind, Options, OutputStyleOption, SortOrder};
@ -38,9 +38,15 @@ impl<'a> Scheduler<'a> {
ExecutorKind::Shell(ref shell) => Box::new(ShellExecutor::new(shell, self.options)),
};
let reference = self
.options
.reference_command
.as_ref()
.map(|cmd| Command::new(None, cmd));
executor.calibrate()?;
for (number, cmd) in self.commands.iter().enumerate() {
for (number, cmd) in reference.iter().chain(self.commands.iter()).enumerate() {
self.results
.push(Benchmark::new(number, cmd, self.options, &*executor).run()?);
@ -65,31 +71,56 @@ impl<'a> Scheduler<'a> {
return;
}
if let Some(annotated_results) = relative_speed::compute_with_check(
let reference = self
.options
.reference_command
.as_ref()
.map(|_| &self.results[0])
.unwrap_or_else(|| relative_speed::fastest_of(&self.results));
if let Some(annotated_results) = relative_speed::compute_with_check_from_reference(
&self.results,
reference,
self.options.sort_order_speed_comparison,
) {
match self.options.sort_order_speed_comparison {
SortOrder::MeanTime => {
println!("{}", "Summary".bold());
let fastest = annotated_results.iter().find(|r| r.is_fastest).unwrap();
let others = annotated_results.iter().filter(|r| !r.is_fastest);
let reference = annotated_results.iter().find(|r| r.is_reference).unwrap();
let others = annotated_results.iter().filter(|r| !r.is_reference);
println!(
" {} ran",
fastest.result.command_with_unused_parameters.cyan()
reference.result.command_with_unused_parameters.cyan()
);
for item in others {
let stddev = if let Some(stddev) = item.relative_speed_stddev {
format!(" ± {}", format!("{:.2}", stddev).green())
} else {
"".into()
};
let comparator = match item.relative_ordering {
Ordering::Less => format!(
"{}{} times slower than",
format!("{:8.2}", item.relative_speed).bold().green(),
stddev
),
Ordering::Greater => format!(
"{}{} times faster than",
format!("{:8.2}", item.relative_speed).bold().green(),
stddev
),
Ordering::Equal => format!(
" As fast ({}{}) as",
format!("{:.2}", item.relative_speed).bold().green(),
stddev
),
};
println!(
"{}{} times faster than {}",
format!("{:8.2}", item.relative_speed).bold().green(),
if let Some(stddev) = item.relative_speed_stddev {
format!(" ± {}", format!("{:.2}", stddev).green())
} else {
"".into()
},
"{} {}",
comparator,
&item.result.command_with_unused_parameters.magenta()
);
}
@ -101,10 +132,10 @@ impl<'a> Scheduler<'a> {
println!(
" {}{} {}",
format!("{:10.2}", item.relative_speed).bold().green(),
if item.is_fastest {
if item.is_reference {
" ".into()
} else if let Some(stddev) = item.relative_speed_stddev {
format!(" ± {}", format!("{:5.2}", stddev).green())
format!(" ± {}", format!("{stddev:5.2}").green())
} else {
" ".into()
},

View File

@ -86,6 +86,16 @@ fn build_command() -> Command {
not every time as would happen with the --prepare option."
),
)
.arg(
Arg::new("reference")
.long("reference")
.action(ArgAction::Set)
.value_name("CMD")
.help(
"The reference command for the relative comparison of results. \
If this is unset, results are compared with the fastest command as reference."
)
)
.arg(
Arg::new("prepare")
.long("prepare")

View File

@ -61,13 +61,14 @@ impl<'a> Command<'a> {
pub fn get_name_with_unused_parameters(&self) -> String {
let parameters = self
.get_unused_parameters()
.map(|(parameter, value)| format!("{} = {}, ", parameter, value.to_string()))
.collect::<String>();
.fold(String::new(), |output, (parameter, value)| {
output + &format!("{parameter} = {value}, ")
});
let parameters = parameters.trim_end_matches(", ");
let parameters = if parameters.is_empty() {
"".into()
} else {
format!(" ({})", parameters)
format!(" ({parameters})")
};
format!("{}{}", self.get_name(), parameters)
@ -80,7 +81,7 @@ impl<'a> Command<'a> {
pub fn get_command(&self) -> Result<std::process::Command> {
let command_line = self.get_command_line();
let mut tokens = shell_words::split(&command_line)
.with_context(|| format!("Failed to parse command '{}'", command_line))?
.with_context(|| format!("Failed to parse command '{command_line}'"))?
.into_iter();
if let Some(program_name) = tokens.next() {
@ -99,17 +100,14 @@ impl<'a> Command<'a> {
pub fn get_unused_parameters(&self) -> impl Iterator<Item = &(&'a str, ParameterValue)> {
self.parameters
.iter()
.filter(move |(parameter, _)| !self.expression.contains(&format!("{{{}}}", parameter)))
.filter(move |(parameter, _)| !self.expression.contains(&format!("{{{parameter}}}")))
}
fn replace_parameters_in(&self, original: &str) -> String {
let mut result = String::new();
let mut replacements = BTreeMap::<String, String>::new();
for (param_name, param_value) in &self.parameters {
replacements.insert(
format!("{{{param_name}}}", param_name = param_name),
param_value.to_string(),
);
replacements.insert(format!("{{{param_name}}}"), param_value.to_string());
}
let mut remaining = original;
// Manually replace consecutive occurrences to avoid double-replacing: e.g.,
@ -319,7 +317,6 @@ impl<'a> Commands<'a> {
let command_names = command_names.map_or(vec![], |names| {
names.map(|v| v.as_str()).collect::<Vec<_>>()
});
let command_strings = command_strings;
let param_name = vals.next().unwrap().as_str();
let param_min = vals.next().unwrap().as_str();
let param_max = vals.next().unwrap().as_str();

View File

@ -32,7 +32,7 @@ impl MarkupExporter for AsciidocExporter {
}
fn command(&self, cmd: &str) -> String {
format!("`{}`", cmd)
format!("`{cmd}`")
}
}
@ -71,8 +71,7 @@ fn test_asciidoc_exporter_table_header() {
#[cfg(test)]
fn cfg_test_table_header(unit_short_name: &str) -> String {
format!(
"[cols=\"<,>,>,>,>\"]\n|===\n| Command \n| Mean [{unit}] \n| Min [{unit}] \n| Max [{unit}] \n| Relative \n",
unit = unit_short_name
"[cols=\"<,>,>,>,>\"]\n|===\n| Command \n| Mean [{unit_short_name}] \n| Min [{unit_short_name}] \n| Max [{unit_short_name}] \n| Relative \n"
)
}

View File

@ -31,7 +31,7 @@ impl Exporter for CsvExporter {
.collect();
if let Some(res) = results.first() {
for param_name in res.parameters.keys() {
headers.push(Cow::Owned(format!("parameter_{}", param_name).into_bytes()));
headers.push(Cow::Owned(format!("parameter_{param_name}").into_bytes()));
}
}
writer.write_record(headers)?;

View File

@ -24,7 +24,7 @@ impl MarkupExporter for MarkdownExporter {
}
fn command(&self, cmd: &str) -> String {
format!("`{}`", cmd)
format!("`{cmd}`")
}
}
@ -53,8 +53,7 @@ fn test_markdown_formatter_table_divider() {
#[cfg(test)]
fn cfg_test_table_header(unit_short_name: String) -> String {
format!(
"| Command | Mean [{unit}] | Min [{unit}] | Max [{unit}] | Relative |\n|:---|---:|---:|---:|---:|\n",
unit = unit_short_name
"| Command | Mean [{unit_short_name}] | Min [{unit_short_name}] | Max [{unit_short_name}] | Relative |\n|:---|---:|---:|---:|---:|\n"
)
}

View File

@ -32,9 +32,9 @@ pub trait MarkupExporter {
// emit table header data
table.push_str(&self.table_row(&[
"Command",
&format!("Mean {}", notation),
&format!("Min {}", notation),
&format!("Max {}", notation),
&format!("Mean {notation}"),
&format!("Min {notation}"),
&format!("Max {notation}"),
"Relative",
]));
@ -56,10 +56,10 @@ pub trait MarkupExporter {
let min_str = format_duration_value(measurement.min, Some(unit)).0;
let max_str = format_duration_value(measurement.max, Some(unit)).0;
let rel_str = format!("{:.2}", entry.relative_speed);
let rel_stddev_str = if entry.is_fastest {
let rel_stddev_str = if entry.is_reference {
"".into()
} else if let Some(stddev) = entry.relative_speed_stddev {
format!(" ± {:.2}", stddev)
format!(" ± {stddev:.2}")
} else {
"".into()
};
@ -67,10 +67,10 @@ pub trait MarkupExporter {
// prepare table row entries
table.push_str(&self.table_row(&[
&self.command(&cmd_str),
&format!("{}{}", mean_str, stddev_str),
&format!("{mean_str}{stddev_str}"),
&min_str,
&max_str,
&format!("{}{}", rel_str, rel_stddev_str),
&format!("{rel_str}{rel_stddev_str}"),
]))
}

View File

@ -108,7 +108,7 @@ impl ExportManager {
ExportTarget::Stdout
} else {
let _ = File::create(filename)
.with_context(|| format!("Could not create export file '{}'", filename))?;
.with_context(|| format!("Could not create export file '{filename}'"))?;
ExportTarget::File(filename.to_string())
},
});
@ -153,5 +153,5 @@ impl ExportManager {
fn write_to_file(filename: &str, content: &[u8]) -> Result<()> {
let mut file = OpenOptions::new().write(true).open(filename)?;
file.write_all(content)
.with_context(|| format!("Failed to export results to '{}'", filename))
.with_context(|| format!("Failed to export results to '{filename}'"))
}

View File

@ -18,7 +18,7 @@ impl MarkupExporter for OrgmodeExporter {
}
fn command(&self, cmd: &str) -> String {
format!("={}=", cmd)
format!("={cmd}=")
}
}
@ -58,8 +58,7 @@ fn test_orgmode_formatter_table_line() {
#[cfg(test)]
fn cfg_test_table_header(unit_short_name: String) -> String {
format!(
"| Command | Mean [{unit}] | Min [{unit}] | Max [{unit}] | Relative |\n|--+--+--+--+--|\n",
unit = unit_short_name
"| Command | Mean [{unit_short_name}] | Min [{unit_short_name}] | Max [{unit_short_name}] | Relative |\n|--+--+--+--+--|\n"
)
}

View File

@ -38,7 +38,7 @@ impl Default for Shell {
impl fmt::Display for Shell {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Shell::Default(cmd) => write!(f, "{}", cmd),
Shell::Default(cmd) => write!(f, "{cmd}"),
Shell::Custom(cmdline) => write!(f, "{}", shell_words::join(cmdline)),
}
}
@ -204,6 +204,9 @@ pub struct Options {
/// Whether or not to ignore non-zero exit codes
pub command_failure_action: CmdFailureAction,
// Command to use as a reference for relative speed comparison
pub reference_command: Option<String>,
/// Command(s) to run before each timing run
pub preparation_command: Option<Vec<String>>,
@ -245,6 +248,7 @@ impl Default for Options {
warmup_count: 0,
min_benchmarking_time: 3.0,
command_failure_action: CmdFailureAction::RaiseError,
reference_command: None,
preparation_command: None,
conclusion_command: None,
setup_command: None,
@ -304,6 +308,8 @@ impl Options {
options.setup_command = matches.get_one::<String>("setup").map(String::from);
options.reference_command = matches.get_one::<String>("reference").map(String::from);
options.preparation_command = matches
.get_many::<String>("prepare")
.map(|values| values.map(String::from).collect::<Vec<String>>());
@ -431,21 +437,25 @@ impl Options {
}
pub fn validate_against_command_list(&self, commands: &Commands) -> Result<()> {
let num_commands = commands.num_commands()
+ if self.reference_command.is_some() {
1
} else {
0
};
if let Some(preparation_command) = &self.preparation_command {
ensure!(
preparation_command.len() <= 1
|| commands.num_commands() == preparation_command.len(),
preparation_command.len() <= 1 || num_commands == preparation_command.len(),
"The '--prepare' option has to be provided just once or N times, where N is the \
number of benchmark commands."
number of benchmark commands including a potential reference."
);
}
if let Some(conclusion_command) = &self.conclusion_command {
ensure!(
conclusion_command.len() <= 1
|| commands.num_commands() == conclusion_command.len(),
conclusion_command.len() <= 1 || num_commands == conclusion_command.len(),
"The '--conclude' option has to be provided just once or N times, where N is the \
number of benchmark commands."
number of benchmark commands including a potential reference."
);
}
@ -457,7 +467,7 @@ impl Options {
fn test_default_shell() {
let shell = Shell::default();
let s = format!("{}", shell);
let s = format!("{shell}");
assert_eq!(&s, DEFAULT_SHELL);
let cmd = shell.command();
@ -468,7 +478,7 @@ fn test_default_shell() {
fn test_can_parse_shell_command_line_from_str() {
let shell = Shell::parse_from_str("shell -x 'aaa bbb'").unwrap();
let s = format!("{}", shell);
let s = format!("{shell}");
assert_eq!(&s, "shell -x 'aaa bbb'");
let cmd = shell.command();

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

View File

@ -26,7 +26,7 @@ impl Unit {
/// Returns the Second value formatted for the Unit.
pub fn format(self, value: Second) -> String {
match self {
Unit::Second => format!("{:.3}", value),
Unit::Second => format!("{value:.3}"),
Unit::MilliSecond => format!("{:.1}", value * 1e3),
Unit::MicroSecond => format!("{:.1}", value * 1e6),
}

View File

@ -54,6 +54,11 @@ impl ExecutionOrderTest {
self.command(output)
}
fn reference(&mut self, output: &str) -> &mut Self {
self.arg("--reference");
self.command(output)
}
fn conclude(&mut self, output: &str) -> &mut Self {
self.arg("--conclude");
self.command(output)
@ -364,3 +369,195 @@ fn multiple_parameter_values() {
.expect_output("command 3 b")
.run();
}
#[test]
fn reference_is_executed_first() {
ExecutionOrderTest::new()
.arg("--runs=1")
.reference("reference")
.command("command 1")
.command("command 2")
.expect_output("reference")
.expect_output("command 1")
.expect_output("command 2")
.run();
}
#[test]
fn reference_is_executed_first_parameter_value() {
ExecutionOrderTest::new()
.arg("--runs=2")
.reference("reference")
.arg("--parameter-list")
.arg("number")
.arg("1,2,3")
.command("command {number}")
.expect_output("reference")
.expect_output("reference")
.expect_output("command 1")
.expect_output("command 1")
.expect_output("command 2")
.expect_output("command 2")
.expect_output("command 3")
.expect_output("command 3")
.run();
}
#[test]
fn reference_is_executed_separately_from_commands() {
ExecutionOrderTest::new()
.arg("--runs=1")
.reference("command 1")
.command("command 1")
.command("command 2")
.expect_output("command 1")
.expect_output("command 1")
.expect_output("command 2")
.run();
}
#[test]
fn setup_prepare_reference_conclude_cleanup_combined() {
ExecutionOrderTest::new()
.arg("--warmup=1")
.arg("--runs=2")
.setup("setup")
.prepare("prepare")
.reference("reference")
.command("command1")
.command("command2")
.conclude("conclude")
.cleanup("cleanup")
// reference
.expect_output("setup")
.expect_output("prepare")
.expect_output("reference")
.expect_output("conclude")
.expect_output("prepare")
.expect_output("reference")
.expect_output("conclude")
.expect_output("prepare")
.expect_output("reference")
.expect_output("conclude")
.expect_output("cleanup")
// 1
.expect_output("setup")
.expect_output("prepare")
.expect_output("command1")
.expect_output("conclude")
.expect_output("prepare")
.expect_output("command1")
.expect_output("conclude")
.expect_output("prepare")
.expect_output("command1")
.expect_output("conclude")
.expect_output("cleanup")
// 2
.expect_output("setup")
.expect_output("prepare")
.expect_output("command2")
.expect_output("conclude")
.expect_output("prepare")
.expect_output("command2")
.expect_output("conclude")
.expect_output("prepare")
.expect_output("command2")
.expect_output("conclude")
.expect_output("cleanup")
.run();
}
#[test]
fn setup_separate_prepare_separate_conclude_cleanup_combined() {
ExecutionOrderTest::new()
.arg("--warmup=1")
.arg("--runs=2")
.setup("setup")
.cleanup("cleanup")
.prepare("prepare1")
.command("command1")
.conclude("conclude1")
.prepare("prepare2")
.command("command2")
.conclude("conclude2")
// 1
.expect_output("setup")
.expect_output("prepare1")
.expect_output("command1")
.expect_output("conclude1")
.expect_output("prepare1")
.expect_output("command1")
.expect_output("conclude1")
.expect_output("prepare1")
.expect_output("command1")
.expect_output("conclude1")
.expect_output("cleanup")
// 2
.expect_output("setup")
.expect_output("prepare2")
.expect_output("command2")
.expect_output("conclude2")
.expect_output("prepare2")
.expect_output("command2")
.expect_output("conclude2")
.expect_output("prepare2")
.expect_output("command2")
.expect_output("conclude2")
.expect_output("cleanup")
.run();
}
#[test]
fn setup_separate_prepare_reference_separate_conclude_cleanup_combined() {
ExecutionOrderTest::new()
.arg("--warmup=1")
.arg("--runs=2")
.setup("setup")
.cleanup("cleanup")
.prepare("prepareref")
.reference("reference")
.conclude("concluderef")
.prepare("prepare1")
.command("command1")
.conclude("conclude1")
.prepare("prepare2")
.command("command2")
.conclude("conclude2")
// reference
.expect_output("setup")
.expect_output("prepareref")
.expect_output("reference")
.expect_output("concluderef")
.expect_output("prepareref")
.expect_output("reference")
.expect_output("concluderef")
.expect_output("prepareref")
.expect_output("reference")
.expect_output("concluderef")
.expect_output("cleanup")
// 1
.expect_output("setup")
.expect_output("prepare1")
.expect_output("command1")
.expect_output("conclude1")
.expect_output("prepare1")
.expect_output("command1")
.expect_output("conclude1")
.expect_output("prepare1")
.expect_output("command1")
.expect_output("conclude1")
.expect_output("cleanup")
// 2
.expect_output("setup")
.expect_output("prepare2")
.expect_output("command2")
.expect_output("conclude2")
.expect_output("prepare2")
.expect_output("command2")
.expect_output("conclude2")
.expect_output("prepare2")
.expect_output("command2")
.expect_output("conclude2")
.expect_output("cleanup")
.run();
}

View File

@ -61,6 +61,17 @@ fn fails_with_wrong_number_of_prepare_options() {
.assert()
.success();
hyperfine()
.arg("--runs=1")
.arg("--prepare=echo ref")
.arg("--prepare=echo a")
.arg("--prepare=echo b")
.arg("--reference=echo ref")
.arg("echo a")
.arg("echo b")
.assert()
.success();
hyperfine()
.arg("--runs=1")
.arg("--prepare=echo a")
@ -73,6 +84,19 @@ fn fails_with_wrong_number_of_prepare_options() {
.stderr(predicate::str::contains(
"The '--prepare' option has to be provided",
));
hyperfine()
.arg("--runs=1")
.arg("--prepare=echo a")
.arg("--prepare=echo b")
.arg("--reference=echo ref")
.arg("echo a")
.arg("echo b")
.assert()
.failure()
.stderr(predicate::str::contains(
"The '--prepare' option has to be provided",
));
}
#[test]
@ -86,6 +110,17 @@ fn fails_with_wrong_number_of_conclude_options() {
.assert()
.success();
hyperfine()
.arg("--runs=1")
.arg("--conclude=echo ref")
.arg("--conclude=echo a")
.arg("--conclude=echo b")
.arg("--reference=echo ref")
.arg("echo a")
.arg("echo b")
.assert()
.success();
hyperfine()
.arg("--runs=1")
.arg("--conclude=echo a")
@ -98,6 +133,19 @@ fn fails_with_wrong_number_of_conclude_options() {
.stderr(predicate::str::contains(
"The '--conclude' option has to be provided",
));
hyperfine()
.arg("--runs=1")
.arg("--conclude=echo a")
.arg("--conclude=echo b")
.arg("--reference=echo ref")
.arg("echo a")
.arg("echo b")
.assert()
.failure()
.stderr(predicate::str::contains(
"The '--conclude' option has to be provided",
));
}
#[test]
@ -413,6 +461,38 @@ fn shows_benchmark_comparison_with_relative_times() {
);
}
#[test]
fn shows_benchmark_comparison_with_same_time() {
hyperfine_debug()
.arg("--command-name=A")
.arg("--command-name=B")
.arg("sleep 1.0")
.arg("sleep 1.0")
.arg("sleep 2.0")
.arg("sleep 1000.0")
.assert()
.success()
.stdout(
predicate::str::contains("As fast (1.00 ± 0.00) as")
.and(predicate::str::contains("2.00 ± 0.00 times faster"))
.and(predicate::str::contains("1000.00 ± 0.00 times faster")),
);
}
#[test]
fn shows_benchmark_comparison_relative_to_reference() {
hyperfine_debug()
.arg("--reference=sleep 2.0")
.arg("sleep 1.0")
.arg("sleep 3.0")
.assert()
.success()
.stdout(
predicate::str::contains("2.00 ± 0.00 times slower")
.and(predicate::str::contains("1.50 ± 0.00 times faster")),
);
}
#[test]
fn performs_all_benchmarks_in_parameter_scan() {
hyperfine_debug()
@ -434,6 +514,29 @@ fn performs_all_benchmarks_in_parameter_scan() {
);
}
#[test]
fn performs_reference_and_all_benchmarks_in_parameter_scan() {
hyperfine_debug()
.arg("--reference=sleep 25")
.arg("--parameter-scan")
.arg("time")
.arg("30")
.arg("45")
.arg("--parameter-step-size")
.arg("5")
.arg("sleep {time}")
.assert()
.success()
.stdout(
predicate::str::contains("Benchmark 1: sleep 25")
.and(predicate::str::contains("Benchmark 2: sleep 30"))
.and(predicate::str::contains("Benchmark 3: sleep 35"))
.and(predicate::str::contains("Benchmark 4: sleep 40"))
.and(predicate::str::contains("Benchmark 5: sleep 45"))
.and(predicate::str::contains("Benchmark 6: sleep 50").not()),
);
}
#[test]
fn intermediate_results_are_not_exported_to_stdout() {
hyperfine_debug()