Compare commits

...
Author SHA1 Message Date
David Peter 36e57044c9 Simplify test 2022-05-15 21:29:36 +02:00
David Peter 066cb732f9 table_line => table_divider 2022-05-15 21:28:35 +02:00
David Peter 79ca2297bb table_data => table_row 2022-05-15 21:14:56 +02:00
David Peter 4c91b36259 Remove superfluous newline 2022-05-15 21:12:07 +02:00
David Peter 9f4951ef6c Move determine_unit_from_results 2022-05-15 21:11:22 +02:00
David Peter b23134b371 Implement Exporter for all MarkupExporters 2022-05-15 21:10:38 +02:00
David Peter a3d9642b2b Remove the TestExporter 2022-05-15 20:46:44 +02:00
David Peter 5b2b5683b7 Do not pass 'unit' into determine_unit_from_results 2022-05-15 20:44:34 +02:00
David Peter 8cd5b1f6bc Move Exporter::unit => determine_unit_from_results 2022-05-15 20:41:55 +02:00
Philipp Paulweber dda9b97078 Refactor MarkupExporter to omit intermediate table result creation and simplify MarkupFormatter emitting
* see: https://github.com/sharkdp/hyperfine/pull/490#pullrequestreview-932424652
2022-04-22 15:58:51 +02:00
Philipp Paulweber 288e9fb4c9 Refactor MarkdownExporter emitting using a generic MarkupFormatter trait
* see: https://github.com/sharkdp/hyperfine/pull/490#issuecomment-1076784074
2022-04-07 00:11:15 +02:00
Philipp Paulweber 5470a08c85 Refactor Markdown table emitting to generic Markup function 2022-04-07 00:11:15 +02:00
Philipp Paulweber 8d815ababf Refactor Markdown table contents generation to generic Markup function 2022-04-07 00:11:15 +02:00
Philipp Paulweber ab03e250a4 Refactor Markdown with Markup by using generic table emitter 2022-04-07 00:11:15 +02:00
dependabot[bot] 7205ac62f2 Bump clap from 3.1.5 to 3.1.7
Bumps [clap](https://github.com/clap-rs/clap) from 3.1.5 to 3.1.7.
- [Release notes](https://github.com/clap-rs/clap/releases)
- [Changelog](https://github.com/clap-rs/clap/blob/master/CHANGELOG.md)
- [Commits](https://github.com/clap-rs/clap/compare/v3.1.5...v3.1.7)

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

Signed-off-by: dependabot[bot] <support@github.com>
2022-04-01 18:03:38 +02:00
dependabot[bot] 775a4a59b3 Bump rust_decimal from 1.22.0 to 1.23.1
Bumps [rust_decimal](https://github.com/paupino/rust-decimal) from 1.22.0 to 1.23.1.
- [Release notes](https://github.com/paupino/rust-decimal/releases)
- [Commits](https://github.com/paupino/rust-decimal/compare/1.22.0...1.23.1)

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

Signed-off-by: dependabot[bot] <support@github.com>
2022-04-01 18:03:26 +02:00
dependabot[bot] d02690c8a8 Bump anyhow from 1.0.55 to 1.0.56
Bumps [anyhow](https://github.com/dtolnay/anyhow) from 1.0.55 to 1.0.56.
- [Release notes](https://github.com/dtolnay/anyhow/releases)
- [Commits](https://github.com/dtolnay/anyhow/compare/1.0.55...1.0.56)

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

Signed-off-by: dependabot[bot] <support@github.com>
2022-04-01 18:03:19 +02:00
dependabot[bot] 716e52d05b Bump libc from 0.2.119 to 0.2.121
Bumps [libc](https://github.com/rust-lang/libc) from 0.2.119 to 0.2.121.
- [Release notes](https://github.com/rust-lang/libc/releases)
- [Commits](https://github.com/rust-lang/libc/compare/0.2.119...0.2.121)

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

Signed-off-by: dependabot[bot] <support@github.com>
2022-04-01 18:03:13 +02:00
David Peter 65844b00b8 Fix description of execution order 2022-03-07 08:49:33 +01:00
David Peter 0ad80759c0 Add execution order to README
closes #247
2022-03-05 13:11:50 +01:00
David Peter 94b40d274e Update execution order image 2022-03-05 13:10:46 +01:00
David Peter 4861321884 Use table for example plots 2022-03-05 13:07:28 +01:00
David Peter 4593572d9d Add whisker plot 2022-03-05 13:02:40 +01:00
David Peter 79f3957879 Update CHANGELOG 2022-03-05 13:01:44 +01:00
David Peter 73efc650de Update README.md 2022-03-05 12:52:02 +01:00
10 changed files with 493 additions and 235 deletions

No files matched your search

+2 -2
View File
@@ -27,8 +27,8 @@
`--shell=none`/`-N` allows users to benchmark very fast commands
(with a runtime on the order of a few milliseconds). See #336, #429,
and #487 (@cipriancraciun and @sharkdp)
- Added `--setup` (`s`) option that can be used to run `make all` or
similar. It runs once per set of tests, like `--cleanup` (`c`).
- Added `--setup`/`-s` option that can be used to run `make all` or
similar. It runs once per set of tests, like `--cleanup`/`-c` (@avar)
- Added new `plot_progression.py` script to debug background interference
effects.
Generated
+8 -8
View File
@@ -13,9 +13,9 @@ dependencies = [
[[package]]
name = "anyhow"
version = "1.0.55"
version = "1.0.56"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "159bb86af3a200e19a068f4224eae4c8bb2d0fa054c7e5d1cacd5cef95e684cd"
checksum = "4361135be9122e0870de935d7c439aef945b9f9ddd4199a553b5270b49c82a27"
[[package]]
name = "approx"
@@ -98,9 +98,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "clap"
version = "3.1.5"
version = "3.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ced1892c55c910c1219e98d6fc8d71f6bddba7905866ce740066d8bfea859312"
checksum = "c67e7973e74896f4bba06ca2dcfd28d54f9cb8c035e940a32b88ed48f5f5ecf2"
dependencies = [
"atty",
"bitflags",
@@ -337,9 +337,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "libc"
version = "0.2.119"
version = "0.2.121"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1bf2e165bb3457c8e098ea76f3e3bc9db55f87aa90d52d0e6be741470916aaa4"
checksum = "efaa7b300f3b5fe8eb6bf21ce3895e1751d9665086af2d64b42f19701015ff4f"
[[package]]
name = "memchr"
@@ -693,9 +693,9 @@ dependencies = [
[[package]]
name = "rust_decimal"
version = "1.22.0"
version = "1.23.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d37baa70cf8662d2ba1c1868c5983dda16ef32b105cce41fb5c47e72936a90b3"
checksum = "22dc69eadbf0ee2110b8d20418c0c6edbaefec2811c4963dc17b6344e11fe0f8"
dependencies = [
"arrayvec",
"num-traits",
+1 -1
View File
@@ -19,7 +19,7 @@ atty = "0.2"
csv = "1.1"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
rust_decimal = "1.19"
rust_decimal = "1.23"
rand = "0.8"
shell-words = "1.0"
thiserror = "1.0"
+25 -6
View File
@@ -128,11 +128,14 @@ hyperfine 'source /tmp/my_function.sh; eval my_function'
hyperfine 'source /tmp/my_alias.sh; eval my_alias'
```
### Export results
### Exporting results
Hyperfine has multiple options for exporting benchmark results: CSV, JSON, Markdown (see `--help`
text for details). To export results to Markdown, for example, you can use the `--export-markdown`
option that will create tables like this:
Hyperfine has multiple options for exporting benchmark results to CSV, JSON, Markdown and other
formats (see `--help` text for details).
#### Markdown
You can use the `--export-markdown <file>` option to create tables like the following:
| Command | Mean [s] | Min [s] | Max [s] | Relative |
|:---|---:|---:|---:|---:|
@@ -140,8 +143,24 @@ option that will create tables like this:
| `find . -iname '*[0-9].jpg'` | 1.427 ± 0.026 | 1.405 | 1.468 | 6.14 ± 0.13 |
| `fd -HI '.*[0-9]\.jpg$'` | 0.232 ± 0.002 | 0.230 | 0.236 | 1.00 |
The JSON output is useful if you want to analyze the benchmark results in more detail. See the
[`scripts/`](https://github.com/sharkdp/hyperfine/tree/master/scripts) folder for some examples.
#### JSON
The JSON output is useful if you want to analyze the benchmark results in more detail. The
[`scripts/`](https://github.com/sharkdp/hyperfine/tree/master/scripts) folder includes a lot
of helpful Python programs to further analyze benchmark results and create helpful
visualizations, like a histogram of runtimes or a whisker plot to comare
multiple benchmarks:
| ![](doc/histogram.png) | ![](doc/whisker.png) |
|---:|---:|
### Detailed benchmark flowchart
The following chart explains the execution order of various timing runs when using options
like `--warmup`, `--prepare <cmd>`, `--setup <cmd>` or `--cleanup <cmd>`:
![](doc/execution-order.png)
## Installation
Binary file not shown.

Before

Width:  |  Height:  |  Size: 94 KiB

After

Width:  |  Height:  |  Size: 71 KiB

+117 -129
View File
@@ -2,16 +2,16 @@
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
width="1724.755"
height="1832.972"
viewBox="0 0 456.34143 484.97387"
width="1502.9366"
height="1822"
viewBox="0 0 397.65199 482.07085"
version="1.1"
id="svg5"
inkscape:version="1.1.1 (3bf5ae0d25, 2021-09-20, custom)"
inkscape:version="1.1.2 (0a00cf5339, 2022-02-04, custom)"
sodipodi:docname="execution-order.svg"
inkscape:export-filename="/home/shark/Informatik/rust/hyperfine/doc/execution-order.png"
inkscape:export-xdpi="44.529999"
inkscape:export-ydpi="44.529999"
inkscape:export-xdpi="38.32"
inkscape:export-ydpi="38.32"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns="http://www.w3.org/2000/svg"
@@ -27,8 +27,8 @@
inkscape:document-units="mm"
showgrid="false"
inkscape:zoom="0.38529391"
inkscape:cx="1064.1227"
inkscape:cy="949.92418"
inkscape:cx="1022.596"
inkscape:cy="939.54249"
inkscape:window-width="1920"
inkscape:window-height="1175"
inkscape:window-x="1920"
@@ -47,10 +47,10 @@
<inkscape:grid
type="xygrid"
id="grid949"
originx="334.94547"
originy="-10.061553" />
originx="323.88106"
originy="-12.964584" />
<sodipodi:guide
position="190.74752,358.77499"
position="179.6831,358.775"
orientation="1,0"
id="guide130046" />
</sodipodi:namedview>
@@ -60,7 +60,7 @@
inkscape:label="Ebene 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(334.94544,-10.06155)">
transform="translate(323.88102,-12.964581)">
<rect
style="fill:#ececec;fill-opacity:1;stroke:#000000;stroke-width:0.481194;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0.80126;stroke-opacity:1;paint-order:stroke fill markers"
id="rect159433"
@@ -118,69 +118,69 @@
transform="matrix(1.1724504,0,0,1.1724504,-222.61922,201.56959)"><tspan
x="-79.596779"
y="-115.14695"
id="tspan14151"><tspan
id="tspan1466"><tspan
style="font-family:'Fira Code';-inkscape-font-specification:'Fira Code'"
id="tspan14149">hyperfine
id="tspan1464">hyperfine
</tspan></tspan><tspan
x="-79.596779"
y="-102.16832"
id="tspan14157"><tspan
id="tspan1472"><tspan
style="font-family:'Fira Code';-inkscape-font-specification:'Fira Code';fill:#e35a00"
id="tspan14153"> --warmup 2</tspan><tspan
id="tspan1468"> --warmup 2</tspan><tspan
style="font-family:'Fira Code';-inkscape-font-specification:'Fira Code'"
id="tspan14155">
id="tspan1470">
</tspan></tspan><tspan
x="-79.596779"
y="-89.189692"
id="tspan14163"><tspan
id="tspan1478"><tspan
style="font-family:'Fira Code';-inkscape-font-specification:'Fira Code';fill:#00bbeb"
id="tspan14159"> --runs 3</tspan><tspan
id="tspan1474"> --runs 3</tspan><tspan
style="font-family:'Fira Code';-inkscape-font-specification:'Fira Code'"
id="tspan14161">
id="tspan1476">
</tspan></tspan><tspan
x="-79.596779"
y="-76.211062"
id="tspan14167"><tspan
id="tspan1482"><tspan
style="font-family:'Fira Code';-inkscape-font-specification:'Fira Code'"
id="tspan14165"> --setup &lt;setup&gt;
id="tspan1480"> --setup &lt;setup&gt;
</tspan></tspan><tspan
x="-79.596779"
y="-63.232432"
id="tspan14171"><tspan
id="tspan1486"><tspan
style="font-family:'Fira Code';-inkscape-font-specification:'Fira Code'"
id="tspan14169"> --prepare &lt;prepare1&gt;
id="tspan1484"> --prepare &lt;prepare1&gt;
</tspan></tspan><tspan
x="-79.596779"
y="-50.253802"
id="tspan14177"><tspan
id="tspan1492"><tspan
style="font-family:'Fira Code';-inkscape-font-specification:'Fira Code';fill:#ffffff"
id="tspan14173"> &lt;command1&gt;</tspan><tspan
id="tspan1488"> &lt;command1&gt;</tspan><tspan
style="font-family:'Fira Code';-inkscape-font-specification:'Fira Code'"
id="tspan14175">
id="tspan1490">
</tspan></tspan><tspan
x="-79.596779"
y="-37.275172"
id="tspan14181"><tspan
id="tspan1496"><tspan
style="font-family:'Fira Code';-inkscape-font-specification:'Fira Code'"
id="tspan14179"> --prepare &lt;prepare2&gt;
id="tspan1494"> --prepare &lt;prepare2&gt;
</tspan></tspan><tspan
x="-79.596779"
y="-24.296542"
id="tspan14185"><tspan
id="tspan1500"><tspan
style="font-family:'Fira Code';-inkscape-font-specification:'Fira Code';fill:#ffffff"
id="tspan14183"> &lt;command2&gt;
id="tspan1498"> &lt;command2&gt;
</tspan></tspan><tspan
x="-79.596779"
y="-11.317913"
id="tspan14189"><tspan
id="tspan1504"><tspan
style="font-family:'Fira Code';-inkscape-font-specification:'Fira Code'"
id="tspan14187"> --cleanup &lt;cleanup&gt;</tspan></tspan></text>
id="tspan1502"> --cleanup &lt;cleanup&gt;</tspan></tspan></text>
<rect
style="fill:#80e5ff;stroke:#000000;stroke-width:0.529167;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0.80126;stroke-opacity:1;paint-order:stroke fill markers"
id="rect6355"
width="58.208336"
height="111.12499"
x="-47.625"
x="-95.249992"
y="116.41667"
ry="0.79374999" />
<rect
@@ -188,7 +188,7 @@
id="rect846"
width="58.20834"
height="74.083336"
x="-47.625"
x="-95.249992"
y="37.041668"
ry="0.79374999" />
<rect
@@ -196,124 +196,124 @@
id="rect1145"
width="47.625"
height="10.583333"
x="-42.333332"
x="-89.958328"
y="137.58333"
ry="0.79374999" />
<text
xml:space="preserve"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:8.81944px;line-height:0;font-family:'Fira Code';-inkscape-font-specification:'Fira Code';fill:#ffffff;stroke-width:0.173299"
x="-40.49472"
x="-88.119713"
y="145.76901"
id="text2821"><tspan
sodipodi:role="line"
id="tspan2819"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:8.81944px;font-family:'Fira Code';-inkscape-font-specification:'Fira Code';fill:#ffffff;stroke-width:0.173299"
x="-40.49472"
x="-88.119713"
y="145.76901">command1</tspan></text>
<rect
style="fill:#ececec;stroke:#000000;stroke-width:0.529167;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0.80126;stroke-opacity:1;paint-order:stroke fill markers"
id="rect4643"
width="47.625"
height="10.583333"
x="-42.333332"
x="-89.958328"
y="121.70834"
ry="0.79374999" />
<text
xml:space="preserve"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:8.81944px;line-height:0;font-family:'Fira Code';-inkscape-font-specification:'Fira Code';stroke-width:0.173299"
x="-40.49472"
x="-88.119713"
y="129.40845"
id="text4647"><tspan
sodipodi:role="line"
id="tspan4645"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:8.81944px;font-family:'Fira Code';-inkscape-font-specification:'Fira Code';stroke-width:0.173299"
x="-40.49472"
x="-88.119713"
y="129.40845">prepare1</tspan></text>
<rect
style="fill:#010101;fill-opacity:1;stroke:#000000;stroke-width:0.529167;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0.80126;stroke-opacity:1;paint-order:stroke fill markers"
id="rect6456"
width="47.625"
height="10.583333"
x="-42.333332"
x="-89.958328"
y="95.249985"
ry="0.79374999" />
<text
xml:space="preserve"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:8.81944px;line-height:0;font-family:'Fira Code';-inkscape-font-specification:'Fira Code';fill:#ffffff;stroke-width:0.173299"
x="-40.49472"
x="-88.119713"
y="103.43568"
id="text6460"><tspan
sodipodi:role="line"
id="tspan6458"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:8.81944px;font-family:'Fira Code';-inkscape-font-specification:'Fira Code';fill:#ffffff;stroke-width:0.173299"
x="-40.49472"
x="-88.119713"
y="103.43568">command1</tspan></text>
<rect
style="fill:#ececec;stroke:#000000;stroke-width:0.529167;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0.80126;stroke-opacity:1;paint-order:stroke fill markers"
id="rect6462"
width="47.625"
height="10.583333"
x="-42.333332"
x="-89.958328"
y="79.375"
ry="0.79374999" />
<text
xml:space="preserve"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:8.81944px;line-height:0;font-family:'Fira Code';-inkscape-font-specification:'Fira Code';stroke-width:0.173299"
x="-40.49472"
x="-88.119713"
y="87.075104"
id="text6466"><tspan
sodipodi:role="line"
id="tspan6464"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:8.81944px;font-family:'Fira Code';-inkscape-font-specification:'Fira Code';stroke-width:0.173299"
x="-40.49472"
x="-88.119713"
y="87.075104">prepare1</tspan></text>
<rect
style="fill:#010101;fill-opacity:1;stroke:#000000;stroke-width:0.529167;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0.80126;stroke-opacity:1;paint-order:stroke fill markers"
id="rect6567"
width="47.625"
height="10.583333"
x="-42.333332"
x="-89.958328"
y="58.208324"
ry="0.79374999" />
<text
xml:space="preserve"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:8.81944px;line-height:0;font-family:'Fira Code';-inkscape-font-specification:'Fira Code';fill:#ffffff;stroke-width:0.173299"
x="-40.49472"
x="-88.119713"
y="66.39402"
id="text6571"><tspan
sodipodi:role="line"
id="tspan6569"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:8.81944px;font-family:'Fira Code';-inkscape-font-specification:'Fira Code';fill:#ffffff;stroke-width:0.173299"
x="-40.49472"
x="-88.119713"
y="66.39402">command1</tspan></text>
<rect
style="fill:#ececec;stroke:#000000;stroke-width:0.529167;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0.80126;stroke-opacity:1;paint-order:stroke fill markers"
id="rect6573"
width="47.625"
height="10.583333"
x="-42.333332"
x="-89.958328"
y="42.333336"
ry="0.79374999" />
<text
xml:space="preserve"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:8.81944px;line-height:0;font-family:'Fira Code';-inkscape-font-specification:'Fira Code';stroke-width:0.173299"
x="-40.49472"
x="-88.119713"
y="50.03344"
id="text6577"><tspan
sodipodi:role="line"
id="tspan6575"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:8.81944px;font-family:'Fira Code';-inkscape-font-specification:'Fira Code';stroke-width:0.173299"
x="-40.49472"
x="-88.119713"
y="50.03344">prepare1</tspan></text>
<text
xml:space="preserve"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:9.76603px;line-height:1;font-family:'Fira Code';-inkscape-font-specification:'Fira Code';fill:#e35a00;fill-opacity:1;stroke-width:0.264583"
x="18.244862"
x="-29.380138"
y="76.524841"
id="text7364"><tspan
sodipodi:role="line"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:9.76603px;font-family:'Fira Code';-inkscape-font-specification:'Fira Code';fill:#e35a00;fill-opacity:1;stroke-width:0.264583"
x="18.244862"
x="-29.380138"
y="76.524841"
id="tspan20001">2 warmup runs</tspan></text>
<text
@@ -322,130 +322,130 @@
x="-16.304935"
y="161.32399"
id="text12858"
transform="translate(34.591878,14.34874)"><tspan
transform="translate(-13.033123,14.34874)"><tspan
x="-16.304935"
y="161.32399"
id="tspan14191">3 benchmark runs</tspan></text>
id="tspan1506">3 benchmark runs</tspan></text>
<rect
style="fill:#b3b3b3;stroke:#000000;stroke-width:0.529167;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0.80126;stroke-opacity:1;paint-order:stroke fill markers"
id="rect13386"
width="47.625"
height="10.583333"
x="-42.333332"
x="-89.958328"
y="21.166664"
ry="0.79374999" />
<text
xml:space="preserve"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:8.81944px;line-height:0;font-family:'Fira Code';-inkscape-font-specification:'Fira Code';stroke-width:0.173299"
x="-40.49472"
x="-88.119713"
y="29.352339"
id="text13390"><tspan
sodipodi:role="line"
id="tspan13388"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:8.81944px;font-family:'Fira Code';-inkscape-font-specification:'Fira Code';stroke-width:0.173299"
x="-40.49472"
x="-88.119713"
y="29.352339">setup</tspan></text>
<rect
style="fill:#b3b3b3;stroke:#000000;stroke-width:0.529167;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0.80126;stroke-opacity:1;paint-order:stroke fill markers"
id="rect37849"
width="47.625"
height="10.583333"
x="-42.333332"
x="-89.958328"
y="232.83333"
ry="0.79374999" />
<text
xml:space="preserve"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:8.81944px;line-height:0;font-family:'Fira Code';-inkscape-font-specification:'Fira Code';stroke-width:0.173299"
x="-40.49472"
x="-88.119713"
y="241.019"
id="text37853"><tspan
sodipodi:role="line"
id="tspan37851"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:8.81944px;font-family:'Fira Code';-inkscape-font-specification:'Fira Code';stroke-width:0.173299"
x="-40.49472"
x="-88.119713"
y="241.019">cleanup</tspan></text>
<rect
style="fill:#010101;fill-opacity:1;stroke:#000000;stroke-width:0.529167;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0.80126;stroke-opacity:1;paint-order:stroke fill markers"
id="rect38128"
width="47.625"
height="10.583333"
x="-42.333332"
x="-89.958328"
y="174.62498"
ry="0.79374999" />
<text
xml:space="preserve"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:8.81944px;line-height:0;font-family:'Fira Code';-inkscape-font-specification:'Fira Code';fill:#ffffff;stroke-width:0.173299"
x="-40.49472"
x="-88.119713"
y="182.81067"
id="text38132"><tspan
sodipodi:role="line"
id="tspan38130"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:8.81944px;font-family:'Fira Code';-inkscape-font-specification:'Fira Code';fill:#ffffff;stroke-width:0.173299"
x="-40.49472"
x="-88.119713"
y="182.81067">command1</tspan></text>
<rect
style="fill:#ececec;stroke:#000000;stroke-width:0.529167;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0.80126;stroke-opacity:1;paint-order:stroke fill markers"
id="rect38134"
width="47.625"
height="10.583333"
x="-42.333332"
x="-89.958328"
y="158.75"
ry="0.79374999" />
<text
xml:space="preserve"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:8.81944px;line-height:0;font-family:'Fira Code';-inkscape-font-specification:'Fira Code';stroke-width:0.173299"
x="-40.49472"
x="-88.119713"
y="166.4501"
id="text38138"><tspan
sodipodi:role="line"
id="tspan38136"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:8.81944px;font-family:'Fira Code';-inkscape-font-specification:'Fira Code';stroke-width:0.173299"
x="-40.49472"
x="-88.119713"
y="166.4501">prepare1</tspan></text>
<rect
style="fill:#010101;fill-opacity:1;stroke:#000000;stroke-width:0.529167;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0.80126;stroke-opacity:1;paint-order:stroke fill markers"
id="rect38140"
width="47.625"
height="10.583333"
x="-42.333332"
x="-89.958328"
y="211.66666"
ry="0.79374999" />
<text
xml:space="preserve"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:8.81944px;line-height:0;font-family:'Fira Code';-inkscape-font-specification:'Fira Code';fill:#ffffff;stroke-width:0.173299"
x="-40.49472"
x="-88.119713"
y="219.85234"
id="text38144"><tspan
sodipodi:role="line"
id="tspan38142"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:8.81944px;font-family:'Fira Code';-inkscape-font-specification:'Fira Code';fill:#ffffff;stroke-width:0.173299"
x="-40.49472"
x="-88.119713"
y="219.85234">command1</tspan></text>
<rect
style="fill:#ececec;stroke:#000000;stroke-width:0.529167;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0.80126;stroke-opacity:1;paint-order:stroke fill markers"
id="rect38146"
width="47.625"
height="10.583333"
x="-42.333332"
x="-89.958328"
y="195.79167"
ry="0.79374999" />
<text
xml:space="preserve"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:8.81944px;line-height:0;font-family:'Fira Code';-inkscape-font-specification:'Fira Code';stroke-width:0.173299"
x="-40.49472"
x="-88.119713"
y="203.49178"
id="text38150"><tspan
sodipodi:role="line"
id="tspan38148"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:8.81944px;font-family:'Fira Code';-inkscape-font-specification:'Fira Code';stroke-width:0.173299"
x="-40.49472"
x="-88.119713"
y="203.49178">prepare1</tspan></text>
<rect
style="fill:#80e5ff;stroke:#000000;stroke-width:0.529167;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0.80126;stroke-opacity:1;paint-order:stroke fill markers"
id="rect272406"
width="58.208336"
height="111.12499"
x="-47.625"
x="-95.249992"
y="359.83334"
ry="0.79374999" />
<rect
@@ -453,7 +453,7 @@
id="rect272408"
width="58.20834"
height="74.083336"
x="-47.625"
x="-95.249992"
y="280.45834"
ry="0.79374999" />
<rect
@@ -461,124 +461,124 @@
id="rect272410"
width="47.625"
height="10.583333"
x="-42.333332"
x="-89.958328"
y="381"
ry="0.79374999" />
<text
xml:space="preserve"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:8.81944px;line-height:0;font-family:'Fira Code';-inkscape-font-specification:'Fira Code';fill:#ffffff;stroke-width:0.173299"
x="-40.49472"
x="-88.119713"
y="389.18567"
id="text272414"><tspan
sodipodi:role="line"
id="tspan272412"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:8.81944px;font-family:'Fira Code';-inkscape-font-specification:'Fira Code';fill:#ffffff;stroke-width:0.173299"
x="-40.49472"
x="-88.119713"
y="389.18567">command2</tspan></text>
<rect
style="fill:#ececec;stroke:#000000;stroke-width:0.529167;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0.80126;stroke-opacity:1;paint-order:stroke fill markers"
id="rect272416"
width="47.625"
height="10.583333"
x="-42.333332"
x="-89.958328"
y="365.125"
ry="0.79374999" />
<text
xml:space="preserve"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:8.81944px;line-height:0;font-family:'Fira Code';-inkscape-font-specification:'Fira Code';stroke-width:0.173299"
x="-40.49472"
x="-88.119713"
y="372.8251"
id="text272420"><tspan
sodipodi:role="line"
id="tspan272418"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:8.81944px;font-family:'Fira Code';-inkscape-font-specification:'Fira Code';stroke-width:0.173299"
x="-40.49472"
x="-88.119713"
y="372.8251">prepare2</tspan></text>
<rect
style="fill:#000000;fill-opacity:1;stroke:#000000;stroke-width:0.529167;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0.80126;stroke-opacity:1;paint-order:stroke fill markers"
id="rect272422"
width="47.625"
height="10.583333"
x="-42.333332"
x="-89.958328"
y="338.66666"
ry="0.79374999" />
<text
xml:space="preserve"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:8.81944px;line-height:0;font-family:'Fira Code';-inkscape-font-specification:'Fira Code';fill:#ffffff;stroke-width:0.173299"
x="-40.49472"
x="-88.119713"
y="346.85236"
id="text272426"><tspan
sodipodi:role="line"
id="tspan272424"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:8.81944px;font-family:'Fira Code';-inkscape-font-specification:'Fira Code';fill:#ffffff;stroke-width:0.173299"
x="-40.49472"
x="-88.119713"
y="346.85236">command2</tspan></text>
<rect
style="fill:#ececec;stroke:#000000;stroke-width:0.529167;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0.80126;stroke-opacity:1;paint-order:stroke fill markers"
id="rect272428"
width="47.625"
height="10.583333"
x="-42.333332"
x="-89.958328"
y="322.79166"
ry="0.79374999" />
<text
xml:space="preserve"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:8.81944px;line-height:0;font-family:'Fira Code';-inkscape-font-specification:'Fira Code';stroke-width:0.173299"
x="-40.49472"
x="-88.119713"
y="330.49176"
id="text272432"><tspan
sodipodi:role="line"
id="tspan272430"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:8.81944px;font-family:'Fira Code';-inkscape-font-specification:'Fira Code';stroke-width:0.173299"
x="-40.49472"
x="-88.119713"
y="330.49176">prepare2</tspan></text>
<rect
style="fill:#000000;fill-opacity:1;stroke:#000000;stroke-width:0.529167;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0.80126;stroke-opacity:1;paint-order:stroke fill markers"
id="rect272434"
width="47.625"
height="10.583333"
x="-42.333332"
x="-89.958328"
y="301.625"
ry="0.79374999" />
<text
xml:space="preserve"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:8.81944px;line-height:0;font-family:'Fira Code';-inkscape-font-specification:'Fira Code';fill:#ffffff;stroke-width:0.173299"
x="-40.49472"
x="-88.119713"
y="309.8107"
id="text272438"><tspan
sodipodi:role="line"
id="tspan272436"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:8.81944px;font-family:'Fira Code';-inkscape-font-specification:'Fira Code';fill:#ffffff;stroke-width:0.173299"
x="-40.49472"
x="-88.119713"
y="309.8107">command2</tspan></text>
<rect
style="fill:#ececec;stroke:#000000;stroke-width:0.529167;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0.80126;stroke-opacity:1;paint-order:stroke fill markers"
id="rect272440"
width="47.625"
height="10.583333"
x="-42.333332"
x="-89.958328"
y="285.75"
ry="0.79374999" />
<text
xml:space="preserve"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:8.81944px;line-height:0;font-family:'Fira Code';-inkscape-font-specification:'Fira Code';stroke-width:0.173299"
x="-40.49472"
x="-88.119713"
y="293.4501"
id="text272444"><tspan
sodipodi:role="line"
id="tspan272442"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:8.81944px;font-family:'Fira Code';-inkscape-font-specification:'Fira Code';stroke-width:0.173299"
x="-40.49472"
x="-88.119713"
y="293.4501">prepare2</tspan></text>
<text
xml:space="preserve"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:9.76603px;line-height:1;font-family:'Fira Code';-inkscape-font-specification:'Fira Code';fill:#e35a00;fill-opacity:1;stroke-width:0.264583"
x="18.244862"
x="-29.380138"
y="319.9415"
id="text272448"><tspan
sodipodi:role="line"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:9.76603px;font-family:'Fira Code';-inkscape-font-specification:'Fira Code';fill:#e35a00;fill-opacity:1;stroke-width:0.264583"
x="18.244862"
x="-29.380138"
y="319.9415"
id="tspan272446">2 warmup runs</tspan></text>
<text
@@ -587,135 +587,123 @@
x="-16.304935"
y="161.32399"
id="text272452"
transform="translate(34.591878,257.76541)"><tspan
transform="translate(-13.033123,257.76541)"><tspan
x="-16.304935"
y="161.32399"
id="tspan14193">3 benchmark runs</tspan></text>
id="tspan1508">3 benchmark runs</tspan></text>
<rect
style="fill:#b3b3b3;stroke:#000000;stroke-width:0.529167;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0.80126;stroke-opacity:1;paint-order:stroke fill markers"
id="rect272454"
width="47.625"
height="10.583333"
x="-42.333332"
x="-89.958328"
y="264.58334"
ry="0.79374999" />
<text
xml:space="preserve"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:8.81944px;line-height:0;font-family:'Fira Code';-inkscape-font-specification:'Fira Code';stroke-width:0.173299"
x="-40.49472"
x="-88.119713"
y="272.76901"
id="text272458"><tspan
sodipodi:role="line"
id="tspan272456"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:8.81944px;font-family:'Fira Code';-inkscape-font-specification:'Fira Code';stroke-width:0.173299"
x="-40.49472"
x="-88.119713"
y="272.76901">setup</tspan></text>
<rect
style="fill:#b3b3b3;stroke:#000000;stroke-width:0.529167;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0.80126;stroke-opacity:1;paint-order:stroke fill markers"
id="rect272460"
width="47.625"
height="10.583333"
x="-42.333332"
x="-89.958328"
y="476.25"
ry="0.79374999" />
<text
xml:space="preserve"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:8.81944px;line-height:0;font-family:'Fira Code';-inkscape-font-specification:'Fira Code';stroke-width:0.173299"
x="-40.49472"
x="-88.119713"
y="484.43567"
id="text272464"><tspan
sodipodi:role="line"
id="tspan272462"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:8.81944px;font-family:'Fira Code';-inkscape-font-specification:'Fira Code';stroke-width:0.173299"
x="-40.49472"
x="-88.119713"
y="484.43567">cleanup</tspan></text>
<rect
style="fill:#000000;fill-opacity:1;stroke:#000000;stroke-width:0.529167;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0.80126;stroke-opacity:1;paint-order:stroke fill markers"
id="rect272466"
width="47.625"
height="10.583333"
x="-42.333332"
x="-89.958328"
y="418.04166"
ry="0.79374999" />
<text
xml:space="preserve"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:8.81944px;line-height:0;font-family:'Fira Code';-inkscape-font-specification:'Fira Code';fill:#ffffff;stroke-width:0.173299"
x="-40.49472"
x="-88.119713"
y="426.22733"
id="text272470"><tspan
sodipodi:role="line"
id="tspan272468"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:8.81944px;font-family:'Fira Code';-inkscape-font-specification:'Fira Code';fill:#ffffff;stroke-width:0.173299"
x="-40.49472"
x="-88.119713"
y="426.22733">command2</tspan></text>
<rect
style="fill:#ececec;stroke:#000000;stroke-width:0.529167;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0.80126;stroke-opacity:1;paint-order:stroke fill markers"
id="rect272472"
width="47.625"
height="10.583333"
x="-42.333332"
x="-89.958328"
y="402.16666"
ry="0.79374999" />
<text
xml:space="preserve"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:8.81944px;line-height:0;font-family:'Fira Code';-inkscape-font-specification:'Fira Code';stroke-width:0.173299"
x="-40.49472"
x="-88.119713"
y="409.86676"
id="text272476"><tspan
sodipodi:role="line"
id="tspan272474"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:8.81944px;font-family:'Fira Code';-inkscape-font-specification:'Fira Code';stroke-width:0.173299"
x="-40.49472"
x="-88.119713"
y="409.86676">prepare2</tspan></text>
<rect
style="fill:#000000;fill-opacity:1;stroke:#000000;stroke-width:0.529167;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0.80126;stroke-opacity:1;paint-order:stroke fill markers"
id="rect272478"
width="47.625"
height="10.583333"
x="-42.333332"
x="-89.958328"
y="455.08331"
ry="0.79374999" />
<text
xml:space="preserve"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:8.81944px;line-height:0;font-family:'Fira Code';-inkscape-font-specification:'Fira Code';fill:#ffffff;stroke-width:0.173299"
x="-40.49472"
x="-88.119713"
y="463.26901"
id="text272482"><tspan
sodipodi:role="line"
id="tspan272480"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:8.81944px;font-family:'Fira Code';-inkscape-font-specification:'Fira Code';fill:#ffffff;stroke-width:0.173299"
x="-40.49472"
x="-88.119713"
y="463.26901">command2</tspan></text>
<rect
style="fill:#ececec;stroke:#000000;stroke-width:0.529167;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0.80126;stroke-opacity:1;paint-order:stroke fill markers"
id="rect272484"
width="47.625"
height="10.583333"
x="-42.333332"
x="-89.958328"
y="439.20834"
ry="0.79374999" />
<text
xml:space="preserve"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:8.81944px;line-height:0;font-family:'Fira Code';-inkscape-font-specification:'Fira Code';stroke-width:0.173299"
x="-40.49472"
x="-88.119713"
y="446.90845"
id="text272488"><tspan
sodipodi:role="line"
id="tspan272486"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:8.81944px;font-family:'Fira Code';-inkscape-font-specification:'Fira Code';stroke-width:0.173299"
x="-40.49472"
x="-88.119713"
y="446.90845">prepare2</tspan></text>
<text
xml:space="preserve"
style="font-size:10.5833px;line-height:1.2;font-family:Audiowide;-inkscape-font-specification:Audiowide;white-space:pre;inline-size:199.93;stroke-width:0.264583"
x="-79.596779"
y="-115.14695"
id="text283737"
transform="matrix(1.7031443,0,0,1.7031443,-192.73007,228.6586)"><tspan
x="-79.596779"
y="-115.14695"
id="tspan14197"><tspan
style="font-weight:bold;font-family:'Segoe UI';-inkscape-font-specification:'Segoe UI Bold'"
id="tspan14195">benchmark execution order</tspan></tspan></text>
</g>
</svg>

Before

Width:  |  Height:  |  Size: 35 KiB

After

Width:  |  Height:  |  Size: 35 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

+67 -89
View File
@@ -1,88 +1,60 @@
use super::Exporter;
use crate::benchmark::benchmark_result::BenchmarkResult;
use crate::benchmark::relative_speed::{self, BenchmarkResultWithRelativeSpeed};
use crate::output::format::format_duration_value;
use crate::util::units::Unit;
use crate::export::markup::MarkupExporter;
use anyhow::{anyhow, Result};
use super::markup::Alignment;
#[derive(Default)]
pub struct MarkdownExporter {}
impl Exporter for MarkdownExporter {
fn serialize(&self, results: &[BenchmarkResult], unit: Option<Unit>) -> Result<Vec<u8>> {
let unit = if let Some(unit) = unit {
// Use the given unit for all entries.
unit
} else if let Some(first_result) = results.first() {
// Use the first BenchmarkResult entry to determine the unit for all entries.
format_duration_value(first_result.mean, None).1
} else {
// Default to `Second`.
Unit::Second
};
impl MarkupExporter for MarkdownExporter {
fn table_row(&self, cells: &[&str]) -> String {
format!("| {} |\n", cells.join(" | "))
}
if let Some(annotated_results) = relative_speed::compute(results) {
let mut destination = start_table(unit);
fn table_divider(&self, cell_aligmnents: &[Alignment]) -> String {
format!(
"|{}\n",
cell_aligmnents
.iter()
.map(|a| match a {
Alignment::Left => ":---|",
Alignment::Right => "---:|",
})
.collect::<String>()
)
}
for result in annotated_results {
add_table_row(&mut destination, &result, unit);
}
Ok(destination)
} else {
Err(anyhow!(
"Relative speed comparison is not available for Markdown export."
))
}
fn command(&self, cmd: &str) -> String {
format!("`{}`", cmd)
}
}
fn table_header(unit_short_name: String) -> String {
/// Check Markdown-based data row formatting
#[test]
fn test_markdown_formatter_table_data() {
let formatter = MarkdownExporter::default();
assert_eq!(formatter.table_row(&["a", "b", "c"]), "| a | b | c |\n");
}
/// Check Markdown-based horizontal line formatting
#[test]
fn test_markdown_formatter_table_divider() {
let formatter = MarkdownExporter::default();
let divider = formatter.table_divider(&[Alignment::Left, Alignment::Right, Alignment::Left]);
assert_eq!(divider, "|:---|---:|:---|\n");
}
/// Test helper function to create unit-based header and horizontal line
/// independently from the markup functionality for Markdown.
#[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
)
}
fn start_table(unit: Unit) -> Vec<u8> {
table_header(unit.short_name()).bytes().collect()
}
fn add_table_row(dest: &mut Vec<u8>, entry: &BenchmarkResultWithRelativeSpeed, unit: Unit) {
let result = &entry.result;
let mean_str = format_duration_value(result.mean, Some(unit)).0;
let stddev_str = if let Some(stddev) = result.stddev {
format!(" ± {}", format_duration_value(stddev, Some(unit)).0)
} else {
"".into()
};
let min_str = format_duration_value(result.min, Some(unit)).0;
let max_str = format_duration_value(result.max, Some(unit)).0;
let rel_str = format!("{:.2}", entry.relative_speed);
let rel_stddev_str = if entry.is_fastest {
"".into()
} else if let Some(stddev) = entry.relative_speed_stddev {
format!(" ± {:.2}", stddev)
} else {
"".into()
};
dest.extend(
format!(
"| `{command}` | {mean}{stddev} | {min} | {max} | {rel}{rel_stddev} |\n",
command = result.command.replace("|", "\\|"),
mean = mean_str,
stddev = stddev_str,
min = min_str,
max = max_str,
rel = rel_str,
rel_stddev = rel_stddev_str,
)
.as_bytes(),
);
}
/// Ensure the markdown output includes the table header and the multiple
/// benchmark results as a table. The list of actual times is not included
/// in the output.
@@ -91,6 +63,8 @@ fn add_table_row(dest: &mut Vec<u8>, entry: &BenchmarkResultWithRelativeSpeed, u
/// the units for all entries when the time unit is not given.
#[test]
fn test_markdown_format_ms() {
use super::Exporter;
use crate::benchmark::benchmark_result::BenchmarkResult;
use std::collections::BTreeMap;
let exporter = MarkdownExporter::default();
@@ -123,23 +97,24 @@ fn test_markdown_format_ms() {
},
];
let formatted = String::from_utf8(exporter.serialize(&timing_results, None).unwrap()).unwrap();
let formatted_expected = format!(
let actual = String::from_utf8(exporter.serialize(&timing_results, None).unwrap()).unwrap();
let expect = format!(
"{}\
| `sleep 0.1` | 105.7 ± 1.6 | 102.3 | 108.0 | 1.00 |
| `sleep 2` | 2005.0 ± 2.0 | 2002.0 | 2008.0 | 18.97 ± 0.29 |
",
table_header("ms".to_string())
cfg_test_table_header("ms".to_string())
);
assert_eq!(formatted_expected, formatted);
assert_eq!(expect, actual);
}
/// This (again) demonstrates that the first entry's units (s) are used to set
/// the units for all entries when the time unit is not given.
#[test]
fn test_markdown_format_s() {
use super::Exporter;
use crate::benchmark::benchmark_result::BenchmarkResult;
use std::collections::BTreeMap;
let exporter = MarkdownExporter::default();
@@ -172,22 +147,24 @@ fn test_markdown_format_s() {
},
];
let formatted = String::from_utf8(exporter.serialize(&timing_results, None).unwrap()).unwrap();
let formatted_expected = format!(
let actual = String::from_utf8(exporter.serialize(&timing_results, None).unwrap()).unwrap();
let expect = format!(
"{}\
| `sleep 2` | 2.005 ± 0.002 | 2.002 | 2.008 | 18.97 ± 0.29 |
| `sleep 0.1` | 0.106 ± 0.002 | 0.102 | 0.108 | 1.00 |
",
table_header("s".to_string())
cfg_test_table_header("s".to_string())
);
assert_eq!(formatted_expected, formatted);
assert_eq!(expect, actual);
}
/// The given time unit (s) is used to set the units for all entries.
#[test]
fn test_markdown_format_time_unit_s() {
use super::Exporter;
use crate::benchmark::benchmark_result::BenchmarkResult;
use crate::util::units::Unit;
use std::collections::BTreeMap;
let exporter = MarkdownExporter::default();
@@ -220,28 +197,30 @@ fn test_markdown_format_time_unit_s() {
},
];
let formatted = String::from_utf8(
let actual = String::from_utf8(
exporter
.serialize(&timing_results, Some(Unit::Second))
.unwrap(),
)
.unwrap();
let formatted_expected = format!(
let expect = format!(
"{}\
| `sleep 0.1` | 0.106 ± 0.002 | 0.102 | 0.108 | 1.00 |
| `sleep 2` | 2.005 ± 0.002 | 2.002 | 2.008 | 18.97 ± 0.29 |
",
table_header("s".to_string())
cfg_test_table_header("s".to_string())
);
assert_eq!(formatted_expected, formatted);
assert_eq!(expect, actual);
}
/// This (again) demonstrates that the given time unit (ms) is used to set
/// the units for all entries.
#[test]
fn test_markdown_format_time_unit_ms() {
use super::Exporter;
use crate::benchmark::benchmark_result::BenchmarkResult;
use crate::util::units::Unit;
use std::collections::BTreeMap;
let exporter = MarkdownExporter::default();
@@ -274,20 +253,19 @@ fn test_markdown_format_time_unit_ms() {
},
];
let formatted = String::from_utf8(
let actual = String::from_utf8(
exporter
.serialize(&timing_results, Some(Unit::MilliSecond))
.unwrap(),
)
.unwrap();
let formatted_expected = format!(
let expect = format!(
"{}\
| `sleep 2` | 2005.0 ± 2.0 | 2002.0 | 2008.0 | 18.97 ± 0.29 |
| `sleep 0.1` | 105.7 ± 1.6 | 102.3 | 108.0 | 1.00 |
",
table_header("ms".to_string())
cfg_test_table_header("ms".to_string())
);
assert_eq!(formatted_expected, formatted);
assert_eq!(expect, actual);
}
+272
View File
@@ -0,0 +1,272 @@
use crate::benchmark::relative_speed::BenchmarkResultWithRelativeSpeed;
use crate::benchmark::{benchmark_result::BenchmarkResult, relative_speed};
use crate::output::format::format_duration_value;
use crate::util::units::Unit;
use super::Exporter;
use anyhow::{anyhow, Result};
pub enum Alignment {
Left,
Right,
}
pub trait MarkupExporter {
fn table_results(&self, entries: &[BenchmarkResultWithRelativeSpeed], unit: Unit) -> String {
// prepare table header strings
let notation = format!("[{}]", unit.short_name());
// emit header
let mut table = self.table_row(&[
"Command",
&format!("Mean {}", notation),
&format!("Min {}", notation),
&format!("Max {}", notation),
"Relative",
]);
// emit horizontal line
table.push_str(&self.table_divider(&[
Alignment::Left,
Alignment::Right,
Alignment::Right,
Alignment::Right,
Alignment::Right,
]));
for entry in entries {
let measurement = &entry.result;
// prepare data row strings
let cmd_str = measurement.command.replace('|', "\\|");
let mean_str = format_duration_value(measurement.mean, Some(unit)).0;
let stddev_str = if let Some(stddev) = measurement.stddev {
format!(" ± {}", format_duration_value(stddev, Some(unit)).0)
} else {
"".into()
};
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 {
"".into()
} else if let Some(stddev) = entry.relative_speed_stddev {
format!(" ± {:.2}", stddev)
} else {
"".into()
};
// prepare table row entries
table.push_str(&self.table_row(&[
&self.command(&cmd_str),
&format!("{}{}", mean_str, stddev_str),
&min_str,
&max_str,
&format!("{}{}", rel_str, rel_stddev_str),
]))
}
table
}
fn table_row(&self, cells: &[&str]) -> String;
fn table_divider(&self, cell_aligmnents: &[Alignment]) -> String;
fn command(&self, size: &str) -> String;
}
fn determine_unit_from_results(results: &[BenchmarkResult]) -> Unit {
if let Some(first_result) = results.first() {
// Use the first BenchmarkResult entry to determine the unit for all entries.
format_duration_value(first_result.mean, None).1
} else {
// Default to `Second`.
Unit::Second
}
}
impl<T: MarkupExporter> Exporter for T {
fn serialize(&self, results: &[BenchmarkResult], unit: Option<Unit>) -> Result<Vec<u8>> {
let unit = unit.unwrap_or_else(|| determine_unit_from_results(&results));
let entries = relative_speed::compute(results);
if entries.is_none() {
return Err(anyhow!(
"Relative speed comparison is not available for markup exporter."
));
}
let table = self.table_results(&entries.unwrap(), unit);
Ok(table.as_bytes().to_vec())
}
}
/// Check unit resolving for timing results and given unit 's'
#[test]
fn test_determine_unit_from_results_unit_given_s() {
use std::collections::BTreeMap;
let results = vec![
BenchmarkResult {
command: String::from("sleep 2"),
mean: 2.0050,
stddev: Some(0.0020),
median: 2.0050,
user: 0.0009,
system: 0.0012,
min: 2.0020,
max: 2.0080,
times: Some(vec![2.0, 2.0, 2.0]),
exit_codes: vec![Some(0), Some(0), Some(0)],
parameters: BTreeMap::new(),
},
BenchmarkResult {
command: String::from("sleep 0.1"),
mean: 0.1057,
stddev: Some(0.0016),
median: 0.1057,
user: 0.0009,
system: 0.0011,
min: 0.1023,
max: 0.1080,
times: Some(vec![0.1, 0.1, 0.1]),
exit_codes: vec![Some(0), Some(0), Some(0)],
parameters: BTreeMap::new(),
},
];
let unit = Some(Unit::Second);
let markup_actual = unit.unwrap_or_else(|| determine_unit_from_results(&results));
let markup_expected = Unit::Second;
assert_eq!(markup_expected, markup_actual);
}
/// Check unit resolving for timing results and given unit 'ms'
#[test]
fn test_determine_unit_from_results_unit_given_ms() {
use std::collections::BTreeMap;
let results = vec![
BenchmarkResult {
command: String::from("sleep 2"),
mean: 2.0050,
stddev: Some(0.0020),
median: 2.0050,
user: 0.0009,
system: 0.0012,
min: 2.0020,
max: 2.0080,
times: Some(vec![2.0, 2.0, 2.0]),
exit_codes: vec![Some(0), Some(0), Some(0)],
parameters: BTreeMap::new(),
},
BenchmarkResult {
command: String::from("sleep 0.1"),
mean: 0.1057,
stddev: Some(0.0016),
median: 0.1057,
user: 0.0009,
system: 0.0011,
min: 0.1023,
max: 0.1080,
times: Some(vec![0.1, 0.1, 0.1]),
exit_codes: vec![Some(0), Some(0), Some(0)],
parameters: BTreeMap::new(),
},
];
let unit = Some(Unit::MilliSecond);
let markup_actual = unit.unwrap_or_else(|| determine_unit_from_results(&results));
let markup_expected = Unit::MilliSecond;
assert_eq!(markup_expected, markup_actual);
}
/// Check unit resolving for timing results using the first result entry as 's'
#[test]
fn test_determine_unit_from_results_unit_first_s() {
use std::collections::BTreeMap;
let results = vec![
BenchmarkResult {
command: String::from("sleep 2"),
mean: 2.0050,
stddev: Some(0.0020),
median: 2.0050,
user: 0.0009,
system: 0.0012,
min: 2.0020,
max: 2.0080,
times: Some(vec![2.0, 2.0, 2.0]),
exit_codes: vec![Some(0), Some(0), Some(0)],
parameters: BTreeMap::new(),
},
BenchmarkResult {
command: String::from("sleep 0.1"),
mean: 0.1057,
stddev: Some(0.0016),
median: 0.1057,
user: 0.0009,
system: 0.0011,
min: 0.1023,
max: 0.1080,
times: Some(vec![0.1, 0.1, 0.1]),
exit_codes: vec![Some(0), Some(0), Some(0)],
parameters: BTreeMap::new(),
},
];
let unit = None;
let markup_actual = unit.unwrap_or_else(|| determine_unit_from_results(&results));
let markup_expected = Unit::Second;
assert_eq!(markup_expected, markup_actual);
}
/// Check unit resolving for timing results using the first result entry as 'ms'
#[test]
fn test_determine_unit_from_results_unit_first_ms() {
use std::collections::BTreeMap;
let results = vec![
BenchmarkResult {
command: String::from("sleep 0.1"),
mean: 0.1057,
stddev: Some(0.0016),
median: 0.1057,
user: 0.0009,
system: 0.0011,
min: 0.1023,
max: 0.1080,
times: Some(vec![0.1, 0.1, 0.1]),
exit_codes: vec![Some(0), Some(0), Some(0)],
parameters: BTreeMap::new(),
},
BenchmarkResult {
command: String::from("sleep 2"),
mean: 2.0050,
stddev: Some(0.0020),
median: 2.0050,
user: 0.0009,
system: 0.0012,
min: 2.0020,
max: 2.0080,
times: Some(vec![2.0, 2.0, 2.0]),
exit_codes: vec![Some(0), Some(0), Some(0)],
parameters: BTreeMap::new(),
},
];
let unit = None;
let markup_actual = unit.unwrap_or_else(|| determine_unit_from_results(&results));
let markup_expected = Unit::MilliSecond;
assert_eq!(markup_expected, markup_actual);
}
/// Check unit resolving for not timing results and no given unit defaulting to 's'
#[test]
fn test_determine_unit_from_results_unit_default_s() {
let results: Vec<BenchmarkResult> = vec![];
let unit = None;
let markup_actual = unit.unwrap_or_else(|| determine_unit_from_results(&results));
let markup_expected = Unit::Second;
assert_eq!(markup_expected, markup_actual);
}
+1
View File
@@ -5,6 +5,7 @@ mod asciidoc;
mod csv;
mod json;
mod markdown;
mod markup;
use self::asciidoc::AsciidocExporter;
use self::csv::CsvExporter;