mirror of
https://github.com/sharkdp/hyperfine.git
synced 2026-11-01 08:50:19 +00:00
Document JSON measurements and omit unavailable memory metrics
This commit is contained in:
1 parent
21bbcc5490
commit
4cd0e24586
9 files changed
+147
-44
No files matched your search
@@ -32,3 +32,50 @@ impl Exporter for JsonExporter {
|
||||
Ok(output?)
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_json_optional_memory() {
|
||||
use crate::benchmark::measurement::{Measurement, Measurements};
|
||||
use crate::quantity::{byte, Information};
|
||||
use serde_json::json;
|
||||
|
||||
for (memory, expected_memory) in [
|
||||
(None, None),
|
||||
(
|
||||
Some(Information::new::<byte>(0.0)),
|
||||
Some(json!({"value": 0.0, "unit": "byte"})),
|
||||
),
|
||||
(
|
||||
Some(Information::new::<byte>(1024.0)),
|
||||
Some(json!({"value": 1024.0, "unit": "byte"})),
|
||||
),
|
||||
] {
|
||||
let result = BenchmarkResult {
|
||||
command: "example".into(),
|
||||
measurements: Measurements::new(vec![Measurement {
|
||||
peak_memory_usage: memory,
|
||||
..Measurement::default()
|
||||
}]),
|
||||
..BenchmarkResult::default()
|
||||
};
|
||||
let output = JsonExporter::default()
|
||||
.serialize(&[result], None, SortOrder::Command)
|
||||
.unwrap();
|
||||
let actual: serde_json::Value = serde_json::from_slice(&output).unwrap();
|
||||
let mut expected = json!({
|
||||
"results": [{
|
||||
"command": "example",
|
||||
"measurements": [{
|
||||
"time_wall_clock": {"value": 0.0, "unit": "second"},
|
||||
"time_user": {"value": 0.0, "unit": "second"},
|
||||
"time_system": {"value": 0.0, "unit": "second"},
|
||||
"exit_code": 0
|
||||
}]
|
||||
}]
|
||||
});
|
||||
if let Some(memory) = expected_memory {
|
||||
expected["results"][0]["measurements"][0]["peak_memory_usage"] = memory;
|
||||
}
|
||||
assert_eq!(actual, expected);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user