Files
hyperfine/src/export/json.rs
T

27 lines
637 B
Rust
Raw Normal View History

2019-05-07 11:55:38 +02:00
use serde::*;
2018-03-20 17:00:24 -04:00
use serde_json::to_vec_pretty;
2021-08-24 21:33:48 +02:00
use super::Exporter;
2022-02-20 13:44:34 +01:00
use crate::benchmark::benchmark_result::BenchmarkResult;
2022-02-06 20:01:41 +01:00
use crate::util::units::Unit;
2021-08-24 21:33:48 +02:00
2022-02-06 17:44:28 +01:00
use anyhow::Result;
#[derive(Serialize, Debug)]
struct HyperfineSummary<'a> {
2019-07-13 10:29:05 +02:00
results: &'a [BenchmarkResult],
}
2018-03-20 17:00:24 -04:00
#[derive(Default)]
pub struct JsonExporter {}
2018-03-20 20:26:28 +01:00
impl Exporter for JsonExporter {
2019-07-13 10:29:05 +02:00
fn serialize(&self, results: &[BenchmarkResult], _unit: Option<Unit>) -> Result<Vec<u8>> {
2018-03-21 22:56:01 +01:00
let mut output = to_vec_pretty(&HyperfineSummary { results });
2022-09-07 09:20:50 +02:00
if let Ok(ref mut content) = output {
2018-03-21 22:56:01 +01:00
content.push(b'\n');
}
2022-02-06 17:44:28 +01:00
Ok(output?)
}
}