Skip to content
Myr

Version the JSON export schema

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by David Peter · committed by David Peter · parent 02b0db5 · Browse files · 2 files+12 added−3 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+12 added−3 removed

  • other:+12 added−3 removed

2 files+12 added−3 removed

modified:src/export/json.rs+6 added-1 removed
8 unmodified lines
9use anyhow::Result;1011#[derive(Serialize, Debug)]12struct HyperfineSummary<'a> {13 schema_version: u32,14 results: &'a [BenchmarkResult],15}1617#[derive(Default)]
6 unmodified lines
24 _time_unit: Option<TimeUnit>,25 _sort_order: SortOrder,26 _reference_index: Option<usize>,27 ) -> Result<Vec<u8>> {27 let mut output = to_vec_pretty(&HyperfineSummary { results });28 let mut output = to_vec_pretty(&HyperfineSummary {29 schema_version: 2,30 results,31 });32 if let Ok(ref mut content) = output {33 content.push(b'\n');34 }35
30 unmodified lines
66 .serialize(&[result], None, SortOrder::Command, None)67 .unwrap();68 let actual: serde_json::Value = serde_json::from_slice(&output).unwrap();69 let mut expected = json!({70 "schema_version": 2,71 "results": [{72 "command": "example",73 "measurements": [{74 "time_wall_clock": {"value": 0.0, "unit": "second"},
12 unmodified lines
modified:README.md+6 added-2 removed
156 unmodified lines
157| `fd -HI '.*[0-9]\.jpg$'` | 0.232 ± 0.002 | 0.230 | 0.236 | 1.00 |158159#### JSON160161The JSON export contains a `results` array with one entry per benchmark. Each entry has a162`measurements` array with one object per measured run (excluding warmup runs):161The JSON export contains a top-level `"schema_version": 2` and a `results` array with one entry162per benchmark. Earlier exports without `schema_version` use the legacy format (version 1).163The schema version is independent of the hyperfine release version and changes when the format164changes incompatibly; adding optional metrics does not require a new schema version.165166Each result has a `measurements` array with one object per measured run (excluding warmup runs):167168| Field | Format | Meaning and platform differences |169|:---|:---|:---|170| `time_wall_clock` | `{ "value": number, "unit": "second" }` | Elapsed time, including time spent waiting or descheduled. Available on all platforms. |171| `time_user` | `{ "value": number, "unit": "second" }` | CPU time spent in user mode, accumulated across threads. On Unix, includes descendants whose usage propagates through parents waiting for them. On Windows, includes processes associated with the benchmark's job object. |
207 unmodified lines