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
Provenance
- Commit
d60eba4- Tree
34dc466- Author
David Peter <mail@david-peter.de>- Committer
David Peter <mail@david-peter.de>- Parent
02b0db5
2 files changed+12 added−3 removed
modified:src/export/json.rs+6 added-1 removed
8 unmodified lines9 use anyhow::Result;10 11 #[derive(Serialize, Debug)]12 struct HyperfineSummary<'a> {13+ schema_version: u32,14 results: &'a [BenchmarkResult],15 }16 17 #[derive(Default)]6 unmodified lines24 _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 lines66 .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 linesmodified:README.md+6 added-2 removed
156 unmodified lines157 | `fd -HI '.*[0-9]\.jpg$'` | 0.232 ± 0.002 | 0.230 | 0.236 | 1.00 |158 159 #### JSON160 161-The 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):161+The JSON export contains a top-level `"schema_version": 2` and a `results` array with one entry162+per benchmark. Earlier exports without `schema_version` use the legacy format (version 1).163+The schema version is independent of the hyperfine release version and changes when the format164+changes incompatibly; adding optional metrics does not require a new schema version.165 166+Each result has a `measurements` array with one object per measured run (excluding warmup runs):167+168 | 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