Refine JSON schema and command metadata

This commit is contained in:
David Peter committed 2026-10-05 18:11:10 +02:00
1 parent c5d3a81fc5
commit 0d86e78ede
15 files changed
+59 -60

No files matched your search

+4 -4
View File
@@ -42,7 +42,7 @@ impl Exporter for CsvExporter {
}
for res in results {
let mut fields = vec![Cow::Borrowed(res.command.as_bytes())];
let mut fields = vec![Cow::Borrowed(res.get_name().as_bytes())];
for f in &[
res.mean_wall_clock_time(),
res.measurements.stddev().unwrap_or_default(),
@@ -80,8 +80,8 @@ fn test_csv() {
let results = vec![
BenchmarkResult {
command: String::from("command_a"),
command_raw: None,
command: String::from("echo command_a"),
name: Some(String::from("command_a")),
measurements: Measurements::new(vec![
Measurement {
time_wall_clock: Time::new::<second>(7.0),
@@ -126,7 +126,7 @@ fn test_csv() {
},
BenchmarkResult {
command: String::from("command_b"),
command_raw: None,
name: None,
measurements: Measurements::new(vec![
Measurement {
time_wall_clock: Time::new::<second>(17.0),
+10 -6
View File
@@ -15,8 +15,11 @@ use anyhow::Result;
mod metadata;
use metadata::Metadata;
const JSON_SCHEMA_VERSION: u32 = 2;
#[derive(Serialize)]
struct HyperfineSummary<'a> {
schema_version: u32,
metadata: &'a Metadata,
results: Vec<JsonBenchmarkResult<'a>>,
}
@@ -116,6 +119,7 @@ impl Exporter for JsonExporter {
_reference_index: Option<usize>,
) -> Result<Vec<u8>> {
let mut output = to_vec_pretty(&HyperfineSummary {
schema_version: JSON_SCHEMA_VERSION,
metadata: &self.metadata,
results: results
.iter()
@@ -182,7 +186,7 @@ fn test_json_optional_memory() {
] {
let result = BenchmarkResult {
command: "example".into(),
command_raw: None,
name: None,
measurements: Measurements::new(vec![Measurement {
peak_memory_usage: memory,
..Measurement::default()
@@ -196,8 +200,8 @@ fn test_json_optional_memory() {
.unwrap();
let actual: serde_json::Value = serde_json::from_slice(&output).unwrap();
let mut expected = json!({
"schema_version": JSON_SCHEMA_VERSION,
"metadata": {
"json_schema_version": metadata::JSON_SCHEMA_VERSION,
"hyperfine_version": env!("CARGO_PKG_VERSION"),
"start_time": "2000-02-29T12:34:56Z",
"platform": exporter.metadata.platform
@@ -250,12 +254,12 @@ fn test_json_summaries_for_parameterized_results() {
.into_iter()
.map(|(size, times)| BenchmarkResult {
command: "example".into(),
command_raw: None,
name: None,
parameters: [(
"size".into(),
Parameter {
value: size.into(),
is_unused: true,
is_unused: size == "small",
},
)]
.into(),
@@ -276,8 +280,8 @@ fn test_json_summaries_for_parameterized_results() {
let actual: serde_json::Value = serde_json::from_slice(&output).unwrap();
let results = actual["results"].as_array().unwrap();
assert_eq!(results.len(), 2);
assert_eq!(results[0]["parameters"]["size"]["value"], "small");
assert_eq!(results[1]["parameters"]["size"]["value"], "large");
assert_eq!(results[0]["parameters"]["size"], json!({"value": "small"}));
assert_eq!(results[1]["parameters"]["size"], json!({"value": "large"}));
assert_eq!(results[0]["measurements"].as_array().unwrap().len(), 2);
assert_eq!(results[1]["measurements"].as_array().unwrap().len(), 1);
assert_eq!(
-4
View File
@@ -1,10 +1,7 @@
use serde::Serialize;
pub(super) const JSON_SCHEMA_VERSION: u32 = 2;
#[derive(Debug, Serialize)]
pub(super) struct Metadata {
json_schema_version: u32,
hyperfine_version: &'static str,
#[serde(skip_serializing_if = "Option::is_none")]
pub start_time: Option<String>,
@@ -14,7 +11,6 @@ pub(super) struct Metadata {
impl Default for Metadata {
fn default() -> Self {
Self {
json_schema_version: JSON_SCHEMA_VERSION,
hyperfine_version: env!("CARGO_PKG_VERSION"),
start_time: utc_now(),
platform: Platform::detect(),
+8 -8
View File
@@ -28,7 +28,7 @@ fn test_markup_export_auto_ms() {
let results = [
BenchmarkResult {
command: String::from("sleep 0.1"),
command_raw: None,
name: None,
measurements: Measurements::new(vec![
Measurement {
time_wall_clock: Time::new::<second>(0.09),
@@ -56,7 +56,7 @@ fn test_markup_export_auto_ms() {
},
BenchmarkResult {
command: String::from("sleep 2"),
command_raw: None,
name: None,
measurements: Measurements::new(vec![
Measurement {
time_wall_clock: Time::new::<second>(2.0),
@@ -129,7 +129,7 @@ fn test_markup_export_auto_s() {
let results = [
BenchmarkResult {
command: String::from("sleep 2"),
command_raw: None,
name: None,
measurements: Measurements::new(vec![
Measurement {
time_wall_clock: Time::new::<second>(2.1),
@@ -157,7 +157,7 @@ fn test_markup_export_auto_s() {
},
BenchmarkResult {
command: String::from("sleep 0.1"),
command_raw: None,
name: None,
measurements: Measurements::new(vec![
Measurement {
time_wall_clock: Time::new::<second>(0.1),
@@ -230,7 +230,7 @@ fn test_markup_export_manual_ms() {
let timing_results = [
BenchmarkResult {
command: String::from("sleep 2"),
command_raw: None,
name: None,
measurements: Measurements::new(vec![
Measurement {
time_wall_clock: Time::new::<second>(2.1),
@@ -258,7 +258,7 @@ fn test_markup_export_manual_ms() {
},
BenchmarkResult {
command: String::from("sleep 0.1"),
command_raw: None,
name: None,
measurements: Measurements::new(vec![
Measurement {
time_wall_clock: Time::new::<second>(0.1),
@@ -330,7 +330,7 @@ fn test_markup_export_manual_s() {
let results = [
BenchmarkResult {
command: String::from("sleep 2"),
command_raw: None,
name: None,
measurements: Measurements::new(vec![
Measurement {
time_wall_clock: Time::new::<second>(2.01),
@@ -358,7 +358,7 @@ fn test_markup_export_manual_s() {
},
BenchmarkResult {
command: String::from("sleep 0.1"),
command_raw: None,
name: None,
measurements: Measurements::new(vec![
Measurement {
time_wall_clock: Time::new::<second>(0.11),