2018-03-22 21:53:36 -04:00
|
|
|
use super::Exporter;
|
2021-08-24 21:24:34 +02:00
|
|
|
use crate::benchmark_result::BenchmarkResult;
|
|
|
|
|
use crate::units::Unit;
|
2018-03-19 17:37:56 -04:00
|
|
|
|
|
|
|
|
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;
|
2018-03-19 17:37:56 -04:00
|
|
|
|
|
|
|
|
#[derive(Serialize, Debug)]
|
|
|
|
|
struct HyperfineSummary<'a> {
|
2019-07-13 10:29:05 +02:00
|
|
|
results: &'a [BenchmarkResult],
|
2018-03-19 17:37:56 -04:00
|
|
|
}
|
|
|
|
|
|
2018-03-20 17:00:24 -04:00
|
|
|
#[derive(Default)]
|
2018-03-19 17:37:56 -04:00
|
|
|
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))
|
2018-03-19 17:37:56 -04:00
|
|
|
}
|
|
|
|
|
}
|