Files
hyperfine/src/export/json.rs
T

27 lines
678 B
Rust
Raw Normal View History

use super::Exporter;
2021-08-24 21:24:34 +02:00
use crate::benchmark_result::BenchmarkResult;
use crate::units::Unit;
use std::io::{Error, ErrorKind, Result};
2019-05-07 11:55:38 +02:00
use serde::*;
2018-03-20 17:00:24 -04:00
use serde_json::to_vec_pretty;
#[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 });
for content in output.iter_mut() {
content.push(b'\n');
}
output.map_err(|e| Error::new(ErrorKind::Other, e))
}
}