mirror of
https://github.com/sharkdp/hyperfine.git
synced 2026-11-01 08:50:19 +00:00
Version the JSON export schema
This commit is contained in:
1 parent
02b0db5c96
commit
d60eba407d
2 files changed
+12
-3
No files matched your search
@@ -158,8 +158,12 @@ You can use the `--export-markdown <file>` option to create tables like the foll
|
|||||||
|
|
||||||
#### JSON
|
#### JSON
|
||||||
|
|
||||||
The JSON export contains a `results` array with one entry per benchmark. Each entry has a
|
The JSON export contains a top-level `"schema_version": 2` and a `results` array with one entry
|
||||||
`measurements` array with one object per measured run (excluding warmup runs):
|
per benchmark. Earlier exports without `schema_version` use the legacy format (version 1).
|
||||||
|
The schema version is independent of the hyperfine release version and changes when the format
|
||||||
|
changes incompatibly; adding optional metrics does not require a new schema version.
|
||||||
|
|
||||||
|
Each result has a `measurements` array with one object per measured run (excluding warmup runs):
|
||||||
|
|
||||||
| Field | Format | Meaning and platform differences |
|
| Field | Format | Meaning and platform differences |
|
||||||
|:---|:---|:---|
|
|:---|:---|:---|
|
||||||
|
|||||||
+6
-1
@@ -10,6 +10,7 @@ use anyhow::Result;
|
|||||||
|
|
||||||
#[derive(Serialize, Debug)]
|
#[derive(Serialize, Debug)]
|
||||||
struct HyperfineSummary<'a> {
|
struct HyperfineSummary<'a> {
|
||||||
|
schema_version: u32,
|
||||||
results: &'a [BenchmarkResult],
|
results: &'a [BenchmarkResult],
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -24,7 +25,10 @@ impl Exporter for JsonExporter {
|
|||||||
_sort_order: SortOrder,
|
_sort_order: SortOrder,
|
||||||
_reference_index: Option<usize>,
|
_reference_index: Option<usize>,
|
||||||
) -> Result<Vec<u8>> {
|
) -> Result<Vec<u8>> {
|
||||||
let mut output = to_vec_pretty(&HyperfineSummary { results });
|
let mut output = to_vec_pretty(&HyperfineSummary {
|
||||||
|
schema_version: 2,
|
||||||
|
results,
|
||||||
|
});
|
||||||
if let Ok(ref mut content) = output {
|
if let Ok(ref mut content) = output {
|
||||||
content.push(b'\n');
|
content.push(b'\n');
|
||||||
}
|
}
|
||||||
@@ -63,6 +67,7 @@ fn test_json_optional_memory() {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
let actual: serde_json::Value = serde_json::from_slice(&output).unwrap();
|
let actual: serde_json::Value = serde_json::from_slice(&output).unwrap();
|
||||||
let mut expected = json!({
|
let mut expected = json!({
|
||||||
|
"schema_version": 2,
|
||||||
"results": [{
|
"results": [{
|
||||||
"command": "example",
|
"command": "example",
|
||||||
"measurements": [{
|
"measurements": [{
|
||||||
|
|||||||
Reference in new issue
Block a user