json.rs
This file
Path
src/export/json.rs
97 lines · 2.5 KiB · Rust
Last changed by
Export selected metrics side by side in CSVDavid Peterbefore adoption067ee70
History of this fileTake it
The walk stopped after 200 commits: lines older than 0f91d0c point at it.
Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 1why, one step back1use std::collections::BTreeMap;Merge pull request #790 from sharkdp/new-metricsDavid Peterbefore adoptionf26c015
line 2why, one step back2Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 3why, one step back3use serde::Serialize;Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c
lines 4–7why, one step back4use serde_json::to_vec_pretty;56use super::Exporter;7use crate::benchmark::benchmark_result::BenchmarkResult;Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 8why, one step back8use crate::metric::{Metric, MetricSelection, Stats};Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c
lines 9–11why, one step back910use anyhow::Result;11Merge pull request #790 from sharkdp/new-metricsDavid Peterbefore adoptionf26c015
lines 12–17why, one step back12mod metadata;13use metadata::Metadata;1415const JSON_SCHEMA_VERSION: u32 = 2;1617#[derive(Serialize)]Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c
line 18why, one step back18struct HyperfineSummary<'a> {Merge pull request #790 from sharkdp/new-metricsDavid Peterbefore adoptionf26c015
lines 19–20why, one step back19 schema_version: u32,20 metadata: &'a Metadata,Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 21why, one step back21 primary_metric: &'static str,Merge pull request #790 from sharkdp/new-metricsDavid Peterbefore adoptionf26c015
line 22why, one step back22 results: Vec<JsonBenchmarkResult<'a>>,Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c
lines 23–24why, one step back23}24Merge pull request #790 from sharkdp/new-metricsDavid Peterbefore adoptionf26c015
lines 25–28why, one step back25#[derive(Serialize)]26struct JsonBenchmarkResult<'a> {27 #[serde(flatten)]28 result: &'a BenchmarkResult,Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 29why, one step back29 summary: BTreeMap<&'static str, StatisticalSummary>,Merge pull request #790 from sharkdp/new-metricsDavid Peterbefore adoptionf26c015
lines 30–33why, one step back30}3132#[derive(Serialize)]33struct StatisticalSummary {Support hardware counters (instructions, cache misses, ...) (#983)David Peterbefore adoptionbc3a3f0
lines 34–35why, one step back34 #[serde(skip_serializing_if = "Option::is_none")]35 unit: Option<&'static str>,Merge pull request #790 from sharkdp/new-metricsDavid Peterbefore adoptionf26c015
lines 36–44why, one step back36 count: usize,37 mean: f64,38 stddev: Option<f64>,39 median: f64,40 min: f64,41 max: f64,42}4344impl StatisticalSummary {Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
lines 45–57why, one step back45 fn new(metric: Metric, stats: Stats) -> Self {46 Self {47 unit: match metric.base_unit().symbol {48 "s" => Some("second"),49 "B" => Some("byte"),50 _ => None,51 },52 count: stats.count,53 mean: stats.mean,54 stddev: stats.stddev,55 median: stats.median,56 min: stats.min,57 max: stats.max,Support hardware counters (instructions, cache misses, ...) (#983)David Peterbefore adoptionbc3a3f0
line 58why, one step back58 }Merge pull request #790 from sharkdp/new-metricsDavid Peterbefore adoptionf26c015
lines 59–61why, one step back59 }60}61Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c
line 62why, one step back62#[derive(Default)]Merge pull request #790 from sharkdp/new-metricsDavid Peterbefore adoptionf26c015
lines 63–65why, one step back63pub struct JsonExporter {64 metadata: Metadata,65}Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c
lines 66–67why, one step back6667impl Exporter for JsonExporter {Export selected metrics side by side in CSVDavid Peterbefore adoption067ee70
lines 68–73why, one step back68 fn serialize(69 &self,70 results: &[BenchmarkResult],71 metrics: &[MetricSelection],72 ) -> Result<Vec<u8>> {73 let primary = metrics[0];Merge pull request #790 from sharkdp/new-metricsDavid Peterbefore adoptionf26c015
lines 74–76why, one step back74 let mut output = to_vec_pretty(&HyperfineSummary {75 schema_version: JSON_SCHEMA_VERSION,76 metadata: &self.metadata,Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 77why, one step back77 primary_metric: primary.metric.name(),Merge pull request #790 from sharkdp/new-metricsDavid Peterbefore adoptionf26c015
lines 78–79why, one step back78 results: results79 .iter()Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 80why, one step back80 .map(|result| JsonBenchmarkResult {Merge pull request #790 from sharkdp/new-metricsDavid Peterbefore adoptionf26c015
line 81why, one step back81 result,Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
lines 82–90why, one step back82 summary: Metric::ALL83 .iter()84 .copied()85 .filter_map(|metric| {86 metric.summarize(&result.measurements).map(|stats| {87 (metric.name(), StatisticalSummary::new(metric, stats))88 })89 })90 .collect(),Merge pull request #790 from sharkdp/new-metricsDavid Peterbefore adoptionf26c015
lines 91–92why, one step back91 })92 .collect(),Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
lines 93–95why, one step back93 })?;94 output.push(b'\n');95 Ok(output)Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c
lines 96–97why, one step back96 }97}