Compare commits

..
Author SHA1 Message Date
David Peter 39b2910415 Update dependabot.yml 2021-05-07 10:09:20 +02:00
dependabot-preview[bot] 8bd60a4e3e Upgrade to GitHub-native Dependabot 2021-04-29 15:04:45 +00:00
n4to4 db45181c88 Fix comment 2021-04-23 12:08:56 +02:00
dependabot-preview[bot] cb59053564 Bump libc from 0.2.85 to 0.2.86
Bumps [libc](https://github.com/rust-lang/libc) from 0.2.85 to 0.2.86.
- [Release notes](https://github.com/rust-lang/libc/releases)
- [Commits](https://github.com/rust-lang/libc/compare/0.2.85...0.2.86)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2021-03-03 14:23:30 +01:00
dependabot-preview[bot] cf2c051812 Bump rust_decimal from 1.10.1 to 1.10.3
Bumps [rust_decimal](https://github.com/paupino/rust-decimal) from 1.10.1 to 1.10.3.
- [Release notes](https://github.com/paupino/rust-decimal/releases)
- [Commits](https://github.com/paupino/rust-decimal/compare/1.10.1...1.10.3)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2021-03-03 14:23:21 +01:00
dependabot-preview[bot] 393122dcde Bump serde_json from 1.0.61 to 1.0.64
Bumps [serde_json](https://github.com/serde-rs/json) from 1.0.61 to 1.0.64.
- [Release notes](https://github.com/serde-rs/json/releases)
- [Commits](https://github.com/serde-rs/json/compare/v1.0.61...v1.0.64)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2021-03-03 14:23:10 +01:00
Benjamin Rosemann 49fcc4be37 Change parameter name in plotting scripts
Change the parameter `imagname` to `output` and provide `-o` shortcut.
2021-02-16 08:21:45 +01:00
Benjamin Rosemann b04a9ec6c4 Add parameters to plotting scripts
Add `imgname` parameter to be able to save a plot to a file instead of
showing it. Use-case: platforms without GUI like docker containers.

Add `labels` parameter to histogram plot. Use-case: replacing long
commands with human friendly labels.
2021-02-16 08:21:45 +01:00
dependabot-preview[bot] 1f7284dae3 Bump libc from 0.2.84 to 0.2.85
Bumps [libc](https://github.com/rust-lang/libc) from 0.2.84 to 0.2.85.
- [Release notes](https://github.com/rust-lang/libc/releases)
- [Commits](https://github.com/rust-lang/libc/compare/0.2.84...0.2.85)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2021-02-14 10:33:15 +01:00
dependabot-preview[bot] d18bdd98d7 Bump libc from 0.2.81 to 0.2.84
Bumps [libc](https://github.com/rust-lang/libc) from 0.2.81 to 0.2.84.
- [Release notes](https://github.com/rust-lang/libc/releases)
- [Commits](https://github.com/rust-lang/libc/compare/0.2.81...0.2.84)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2021-02-07 22:28:46 +01:00
dependabot-preview[bot] 89700a244c Bump rand from 0.8.0 to 0.8.3
Bumps [rand](https://github.com/rust-random/rand) from 0.8.0 to 0.8.3.
- [Release notes](https://github.com/rust-random/rand/releases)
- [Changelog](https://github.com/rust-random/rand/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rust-random/rand/commits)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2021-02-07 22:28:38 +01:00
dependabot-preview[bot] 5f949b17ad Bump serde from 1.0.118 to 1.0.123
Bumps [serde](https://github.com/serde-rs/serde) from 1.0.118 to 1.0.123.
- [Release notes](https://github.com/serde-rs/serde/releases)
- [Commits](https://github.com/serde-rs/serde/compare/v1.0.118...v1.0.123)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2021-02-07 22:28:21 +01:00
dependabot-preview[bot] 77fcb6a6b3 Bump rust_decimal from 1.9.0 to 1.10.1
Bumps [rust_decimal](https://github.com/paupino/rust-decimal) from 1.9.0 to 1.10.1.
- [Release notes](https://github.com/paupino/rust-decimal/releases)
- [Commits](https://github.com/paupino/rust-decimal/compare/1.9.0...1.10.1)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2021-02-07 22:28:14 +01:00
dependabot-preview[bot] 80b6bdb90b Bump rand from 0.7.3 to 0.8.0
Bumps [rand](https://github.com/rust-random/rand) from 0.7.3 to 0.8.0.
- [Release notes](https://github.com/rust-random/rand/releases)
- [Changelog](https://github.com/rust-random/rand/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rust-random/rand/compare/0.7.3...0.8.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2021-01-01 19:40:37 +01:00
dependabot-preview[bot] 0ab24d49b3 Bump serde_json from 1.0.59 to 1.0.61
Bumps [serde_json](https://github.com/serde-rs/json) from 1.0.59 to 1.0.61.
- [Release notes](https://github.com/serde-rs/json/releases)
- [Commits](https://github.com/serde-rs/json/compare/v1.0.59...v1.0.61)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2021-01-01 08:06:55 +01:00
dependabot-preview[bot] cf0ce696a7 Bump rust_decimal from 1.8.1 to 1.9.0
Bumps [rust_decimal](https://github.com/paupino/rust-decimal) from 1.8.1 to 1.9.0.
- [Release notes](https://github.com/paupino/rust-decimal/releases)
- [Commits](https://github.com/paupino/rust-decimal/compare/1.8.1...1.9.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2021-01-01 08:06:38 +01:00
dependabot-preview[bot] 2e4bce63d3 Bump libc from 0.2.80 to 0.2.81
Bumps [libc](https://github.com/rust-lang/libc) from 0.2.80 to 0.2.81.
- [Release notes](https://github.com/rust-lang/libc/releases)
- [Commits](https://github.com/rust-lang/libc/compare/0.2.80...0.2.81)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2021-01-01 08:06:30 +01:00
dependabot-preview[bot] 53bc46f6b6 Bump serde from 1.0.117 to 1.0.118
Bumps [serde](https://github.com/serde-rs/serde) from 1.0.117 to 1.0.118.
- [Release notes](https://github.com/serde-rs/serde/releases)
- [Commits](https://github.com/serde-rs/serde/compare/v1.0.117...v1.0.118)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2021-01-01 08:05:34 +01:00
dependabot-preview[bot] a4d9c5eff7 Bump csv from 1.1.3 to 1.1.5
Bumps [csv](https://github.com/BurntSushi/rust-csv) from 1.1.3 to 1.1.5.
- [Release notes](https://github.com/BurntSushi/rust-csv/releases)
- [Commits](https://github.com/BurntSushi/rust-csv/compare/1.1.3...1.1.5)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-12-01 16:04:34 +01:00
David Peter 907d38aa18 Only show title if it is set 2020-11-03 13:46:16 +01:00
dependabot-preview[bot] 3553812436 Bump approx from 0.3.2 to 0.4.0
Bumps [approx](https://github.com/brendanzab/approx) from 0.3.2 to 0.4.0.
- [Release notes](https://github.com/brendanzab/approx/releases)
- [Commits](https://github.com/brendanzab/approx/commits)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-11-01 09:53:01 +01:00
dependabot-preview[bot] 591cce786a Bump cfg-if from 0.1.10 to 1.0.0
Bumps [cfg-if](https://github.com/alexcrichton/cfg-if) from 0.1.10 to 1.0.0.
- [Release notes](https://github.com/alexcrichton/cfg-if/releases)
- [Commits](https://github.com/alexcrichton/cfg-if/compare/0.1.10...1.0.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-11-01 07:24:36 +01:00
dependabot-preview[bot] 1d5626207a Bump libc from 0.2.79 to 0.2.80
Bumps [libc](https://github.com/rust-lang/libc) from 0.2.79 to 0.2.80.
- [Release notes](https://github.com/rust-lang/libc/releases)
- [Commits](https://github.com/rust-lang/libc/compare/0.2.79...0.2.80)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-11-01 07:22:51 +01:00
Thiago Arrais 8704e76d36 Incorporate suggestions from review 2020-10-26 20:38:45 +01:00
Thiago Arrais e1fea57182 Adds tip for benchmarking aliases and functions 2020-10-26 20:38:45 +01:00
Julian Kaindl c05d7f9480 Add command exit code to output if it fails 2020-10-25 19:04:17 +01:00
Martin Junghanns 990ed45c3a Create export file before first benchmark (#340) 2020-10-18 09:15:44 +02:00
Martin Junghanns 2547342644 Update changelog 2020-10-18 09:13:56 +02:00
Martin Junghanns d7e6fa6dfb Export intermediate results after each benchmark command 2020-10-18 09:13:56 +02:00
12 changed files with 160 additions and 72 deletions

No files matched your search

+8
View File
@@ -0,0 +1,8 @@
version: 2
updates:
- package-ecosystem: cargo
directory: "/"
schedule:
interval: monthly
time: "04:00"
timezone: Europe/Berlin
+7
View File
@@ -1,9 +1,16 @@
# unreleased
- Add command exit code to output if it fails, see #342 (@KaindlJulian)
## Features
## Changes
- When `--export-*` commands are used, result files are created before benchmark execution
to fail early in case of, e.g., wrong permissions. See #306 (@s1ck).
- When `--export-*` options are used, result files are written after each individual
benchmark command instead of writing after all benchmarks have finished. See #306 (@s1ck).
## Bugfixes
## Other
Generated
+47 -35
View File
@@ -11,13 +11,19 @@ dependencies = [
[[package]]
name = "approx"
version = "0.3.2"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0e60b75072ecd4168020818c0107f2857bb6c4e64252d8d3983f6263b40a5c3"
checksum = "3f2a05fd1bd10b2527e20a2cd32d8873d115b8b39fe219ee25f42a8aca6ba278"
dependencies = [
"num-traits",
]
[[package]]
name = "arrayvec"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b"
[[package]]
name = "atty"
version = "0.2.14"
@@ -71,6 +77,12 @@ version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "clap"
version = "2.33.3"
@@ -126,9 +138,9 @@ dependencies = [
[[package]]
name = "csv"
version = "1.1.3"
version = "1.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "00affe7f6ab566df61b4be3ce8cf16bc2576bca0963ceb0955e45d514bf9a279"
checksum = "f9d58633299b24b515ac72a3f869f8b91306a3cec616a602843a383acd6f9e97"
dependencies = [
"bstr",
"csv-core",
@@ -160,11 +172,11 @@ checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba"
[[package]]
name = "getrandom"
version = "0.1.15"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fc587bc0ec293155d5bfa6b9891ec18a1e330c234f896ea47fbada4cadbe47e6"
checksum = "ee8025cf36f917e6a52cce185b7c7177689b838b7ec138364e50cc2277a56cf4"
dependencies = [
"cfg-if",
"cfg-if 0.1.10",
"libc",
"wasi",
]
@@ -184,13 +196,13 @@ version = "1.11.0"
dependencies = [
"approx",
"atty",
"cfg-if",
"cfg-if 1.0.0",
"clap",
"colored",
"csv",
"indicatif",
"libc",
"rand 0.7.3",
"rand 0.8.3",
"rust_decimal",
"serde",
"serde_json",
@@ -225,9 +237,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "libc"
version = "0.2.79"
version = "0.2.86"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2448f6066e80e3bfc792e9c98bf705b4b0fc6e8ef5b43e5889aff0eaa9c58743"
checksum = "b7282d924be3275cec7f6756ff4121987bc6481325397dde6ba3e7802b1a8b1c"
[[package]]
name = "memchr"
@@ -363,15 +375,14 @@ dependencies = [
[[package]]
name = "rand"
version = "0.7.3"
version = "0.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03"
checksum = "0ef9e7e66b4468674bfcb0c81af8b7fa0bb154fa9f28eb840da5c447baeb8d7e"
dependencies = [
"getrandom",
"libc",
"rand_chacha 0.2.2",
"rand_core 0.5.1",
"rand_hc 0.2.0",
"rand_chacha 0.3.0",
"rand_core 0.6.0",
"rand_hc 0.3.0",
]
[[package]]
@@ -386,12 +397,12 @@ dependencies = [
[[package]]
name = "rand_chacha"
version = "0.2.2"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402"
checksum = "e12735cf05c9e10bf21534da50a147b924d555dc7a547c42e6bb2d5b6017ae0d"
dependencies = [
"ppv-lite86",
"rand_core 0.5.1",
"rand_core 0.6.0",
]
[[package]]
@@ -411,9 +422,9 @@ checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc"
[[package]]
name = "rand_core"
version = "0.5.1"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19"
checksum = "a8b34ba8cfb21243bd8df91854c830ff0d785fff2e82ebd4434c2644cb9ada18"
dependencies = [
"getrandom",
]
@@ -429,11 +440,11 @@ dependencies = [
[[package]]
name = "rand_hc"
version = "0.2.0"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c"
checksum = "3190ef7066a446f2e7f42e239d161e905420ccab01eb967c9eb27d21b2322a73"
dependencies = [
"rand_core 0.5.1",
"rand_core 0.6.0",
]
[[package]]
@@ -524,10 +535,11 @@ checksum = "8cab7a364d15cde1e505267766a2d3c4e22a843e1a601f0fa7564c0f82ced11c"
[[package]]
name = "rust_decimal"
version = "1.8.1"
version = "1.10.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c9e81662973c7a8d9663e64a0de4cd642b89a21d64966e3d99606efdc5fb0cc6"
checksum = "dc7f5b8840fb1f83869a3e1dfd06d93db79ea05311ac5b42b8337d3371caa4f1"
dependencies = [
"arrayvec",
"num-traits",
"serde",
]
@@ -540,18 +552,18 @@ checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e"
[[package]]
name = "serde"
version = "1.0.117"
version = "1.0.123"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b88fa983de7720629c9387e9f517353ed404164b1e482c970a90c1a4aaf7dc1a"
checksum = "92d5161132722baa40d802cc70b15262b98258453e85e5d1d365c757c73869ae"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.117"
version = "1.0.123"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cbd1ae72adb44aab48f325a02444a5fc079349a8d804c1fc922aed3f7454c74e"
checksum = "9391c295d64fc0abb2c556bad848f33cb8296276b1ad2677d1ae1ace4f258f31"
dependencies = [
"proc-macro2",
"quote",
@@ -560,9 +572,9 @@ dependencies = [
[[package]]
name = "serde_json"
version = "1.0.59"
version = "1.0.64"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dcac07dbffa1c65e7f816ab9eba78eb142c6d44410f4eeba1e26e4f5dfa56b95"
checksum = "799e97dc9fdae36a5c8b8f2cae9ce2ee9fdce2058c57a93e6099d919fd982f79"
dependencies = [
"itoa",
"ryu",
@@ -587,9 +599,9 @@ checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
[[package]]
name = "syn"
version = "1.0.44"
version = "1.0.60"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e03e57e4fcbfe7749842d53e24ccb9aa12b7252dbe5e91d2acad31834c8b8fdd"
checksum = "c700597eca8a5a762beb35753ef6b94df201c81cca676604f547495a0d7f0081"
dependencies = [
"proc-macro2",
"quote",
+5 -5
View File
@@ -16,12 +16,12 @@ colored = "2.0"
indicatif = "0.15"
statistical = "1.0"
atty = "0.2"
cfg-if = "0.1"
csv = "1.1.3"
cfg-if = "1.0"
csv = "1.1.5"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
rust_decimal = "1.8"
rand = "0.7"
rust_decimal = "1.10"
rand = "0.8"
[target.'cfg(not(windows))'.dependencies]
libc = "0.2"
@@ -35,7 +35,7 @@ default-features = false
features = ["suggestions", "color", "wrap_help"]
[dev-dependencies]
approx = "0.3"
approx = "0.4"
[build-dependencies]
clap = "2"
+20
View File
@@ -77,6 +77,26 @@ hyperfine --parameter-scan delay 0.3 0.7 -D 0.2 'sleep {delay}'
```
This runs `sleep 0.3`, `sleep 0.5` and `sleep 0.7`.
### Shell functions and aliases
If you are using bash, you can export shell functions to directly benchmark them with hyperfine:
```
$ my_function() { sleep 1; }
$ export -f my_function
$ hyperfine my_function
```
If you are using a different shell, or if you want to benchmark shell aliases, you may try to put
them in a separate file:
```bash
echo 'my_function() { sleep 1 }' > /tmp/my_function.sh
echo 'alias my_alias="sleep 1"' > /tmp/my_alias.sh
hyperfine 'source /tmp/my_function.sh; eval my_function'
hyperfine 'source /tmp/my_alias.sh; eval my_alias'
```
### Export results
Hyperfine has multiple options for exporting benchmark results: CSV, JSON, Markdown (see `--help`
+16 -3
View File
@@ -10,16 +10,26 @@ 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(
"--labels", help="Comma-separated list of entries for the plot legend"
)
parser.add_argument("--bins", help="Number of bins (default: auto)")
parser.add_argument(
"--type", help="Type of histogram (*bar*, barstacked, step, stepfilled)"
)
parser.add_argument(
"-o", "--output", help="Save image to the given filename."
)
args = parser.parse_args()
with open(args.file) as f:
results = json.load(f)["results"]
commands = [b["command"] for b in results]
if args.labels:
labels = args.labels.split(",")
else:
labels = [b["command"] for b in results]
all_times = [b["times"] for b in results]
t_min = np.min(list(map(np.min, all_times)))
@@ -29,7 +39,7 @@ bins = int(args.bins) if args.bins else "auto"
histtype = args.type if args.type else "bar"
plt.hist(
all_times, label=commands, bins=bins, histtype=histtype, range=(t_min, t_max),
all_times, label=labels, bins=bins, histtype=histtype, range=(t_min, t_max),
)
plt.legend(prop={"family": ["Source Code Pro", "Fira Mono", "Courier New"]})
@@ -37,4 +47,7 @@ plt.xlabel("Time [s]")
if args.title:
plt.title(args.title)
plt.show()
if args.output:
plt.savefig(args.output)
else:
plt.show()
+7 -1
View File
@@ -25,6 +25,9 @@ parser.add_argument(
parser.add_argument(
"--titles", help="Comma-separated list of titles for the plot legend"
)
parser.add_argument(
"-o", "--output", help="Save image to the given filename."
)
args = parser.parse_args()
if args.parameter_name is not None:
@@ -100,4 +103,7 @@ if args.log_x:
if args.titles:
plt.legend(args.titles.split(","))
plt.show()
if args.output:
plt.savefig(args.output)
else:
plt.show()
+10 -2
View File
@@ -18,6 +18,10 @@ parser.add_argument("--title", help="Plot Title")
parser.add_argument(
"--labels", help="Comma-separated list of entries for the plot legend"
)
parser.add_argument(
"-o", "--output", help="Save image to the given filename."
)
args = parser.parse_args()
with open(args.file) as f:
@@ -36,8 +40,12 @@ colors = [cmap(val / len(times)) for val in range(len(times))]
for patch, color in zip(boxplot["boxes"], colors):
patch.set_facecolor(color)
plt.title(args.title)
if args.title:
plt.title(args.title)
plt.legend(handles=boxplot["boxes"], labels=labels, loc="best", fontsize="medium")
plt.ylabel("Time [s]")
plt.ylim(0, None)
plt.show()
if args.output:
plt.savefig(args.output)
else:
plt.show()
+9 -3
View File
@@ -63,9 +63,15 @@ pub fn time_shell_command(
if failure_action == CmdFailureAction::RaiseError && !result.status.success() {
return Err(io::Error::new(
io::ErrorKind::Other,
"Command terminated with non-zero exit code. \
Use the '-i'/'--ignore-failure' option if you want to ignore this. \
Alternatively, use the '--show-output' option to debug what went wrong.",
format!(
"{}. \
Use the '-i'/'--ignore-failure' option if you want to ignore this. \
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)
)
),
));
}
+8 -4
View File
@@ -8,7 +8,7 @@ use self::csv::CsvExporter;
use self::json::JsonExporter;
use self::markdown::MarkdownExporter;
use std::fs::File;
use std::fs::{File, OpenOptions};
use std::io::{Result, Write};
use crate::hyperfine::types::BenchmarkResult;
@@ -55,7 +55,9 @@ impl ExportManager {
}
/// Add an additional exporter to the ExportManager
pub fn add_exporter(&mut self, export_type: ExportType, filename: &str) {
pub fn add_exporter(&mut self, export_type: ExportType, filename: &str) -> Result<()> {
let _ = File::create(filename)?;
let exporter: Box<dyn Exporter> = match export_type {
ExportType::Asciidoc => Box::new(AsciidocExporter::default()),
ExportType::Csv => Box::new(CsvExporter::default()),
@@ -66,10 +68,12 @@ impl ExportManager {
exporter,
filename: filename.to_string(),
});
Ok(())
}
/// Write the given results to all Exporters contained within this manager
pub fn write_results(&self, results: Vec<BenchmarkResult>, unit: Option<Unit>) -> Result<()> {
pub fn write_results(&self, results: &[BenchmarkResult], unit: Option<Unit>) -> Result<()> {
for e in &self.exporters {
let file_content = e.exporter.serialize(&results, unit)?;
write_to_file(&e.filename, &file_content)?;
@@ -80,6 +84,6 @@ impl ExportManager {
/// Write the given content to a file with the specified name
fn write_to_file(filename: &str, content: &[u8]) -> Result<()> {
let mut file = File::create(filename)?;
let mut file = OpenOptions::new().write(true).open(filename)?;
file.write_all(content)
}
+1 -1
View File
@@ -13,7 +13,7 @@ pub const OUTLIER_THRESHOLD: f64 = 1.4826 * 10.0;
/// Compute modifized Z-scores for a given sample. A (unmodified) Z-score is defined by
/// `(x_i - x_mean)/x_stddev` whereas the modified Z-score is defined by `(x_i - x_median)/MAD`
/// where MAD is the median average deviation.
/// where MAD is the median absolute deviation.
///
/// References:
/// - <https://en.wikipedia.org/wiki/Median_absolute_deviation>
+22 -18
View File
@@ -49,6 +49,15 @@ fn run(
// Run the benchmarks
for (num, cmd) in commands.iter().enumerate() {
timing_results.push(run_benchmark(num, cmd, shell_spawning_time, options)?);
// Export (intermediate) results
let ans = export_manager.write_results(&timing_results, options.time_unit);
if let Err(e) = ans {
error(&format!(
"The following error occurred while exporting: {}",
e
));
}
}
// Print relative speed comparison
@@ -56,23 +65,17 @@ fn run(
write_benchmark_comparison(&timing_results);
}
// Export results
let ans = export_manager.write_results(timing_results, options.time_unit);
if let Err(e) = ans {
error(&format!(
"The following error occurred while exporting: {}",
e
));
}
Ok(())
}
fn main() {
let matches = get_arg_matches(env::args_os());
let options = build_hyperfine_options(&matches);
let export_manager = build_export_manager(&matches);
let commands = build_commands(&matches);
let export_manager = match build_export_manager(&matches) {
Ok(export_manager) => export_manager,
Err(ref e) => error(&e.to_string())
};
let res = match options {
Ok(ref opts) => run(&commands, &opts, &export_manager),
@@ -202,20 +205,21 @@ fn build_hyperfine_options<'a>(
/// Build the ExportManager that will export the results specified
/// in the given ArgMatches
fn build_export_manager(matches: &ArgMatches<'_>) -> ExportManager {
fn build_export_manager(matches: &ArgMatches<'_>) -> io::Result<ExportManager> {
let mut export_manager = ExportManager::new();
{
let mut add_exporter = |flag, exporttype| {
let mut add_exporter = |flag, exporttype| -> io::Result<()> {
if let Some(filename) = matches.value_of(flag) {
export_manager.add_exporter(exporttype, filename);
export_manager.add_exporter(exporttype, filename)?;
}
Ok(())
};
add_exporter("export-asciidoc", ExportType::Asciidoc);
add_exporter("export-json", ExportType::Json);
add_exporter("export-csv", ExportType::Csv);
add_exporter("export-markdown", ExportType::Markdown);
add_exporter("export-asciidoc", ExportType::Asciidoc)?;
add_exporter("export-json", ExportType::Json)?;
add_exporter("export-csv", ExportType::Csv)?;
add_exporter("export-markdown", ExportType::Markdown)?;
}
export_manager
Ok(export_manager)
}
/// Build the commands to benchmark