mirror of
https://github.com/sharkdp/hyperfine.git
synced 2026-10-31 00:40:18 +00:00
34 lines
736 B
Rust
34 lines
736 B
Rust
use serde::*;
|
|
use serde_json::to_vec_pretty;
|
|
|
|
use super::Exporter;
|
|
use crate::benchmark::benchmark_result::BenchmarkResult;
|
|
use crate::options::SortOrder;
|
|
use crate::quantity::TimeUnit;
|
|
|
|
use anyhow::Result;
|
|
|
|
#[derive(Serialize, Debug)]
|
|
struct HyperfineSummary<'a> {
|
|
results: &'a [BenchmarkResult],
|
|
}
|
|
|
|
#[derive(Default)]
|
|
pub struct JsonExporter {}
|
|
|
|
impl Exporter for JsonExporter {
|
|
fn serialize(
|
|
&self,
|
|
results: &[BenchmarkResult],
|
|
_unit: Option<TimeUnit>,
|
|
_sort_order: SortOrder,
|
|
) -> Result<Vec<u8>> {
|
|
let mut output = to_vec_pretty(&HyperfineSummary { results });
|
|
if let Ok(ref mut content) = output {
|
|
content.push(b'\n');
|
|
}
|
|
|
|
Ok(output?)
|
|
}
|
|
}
|