Skip to content
Myr

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 file

Take 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 back
1use std::collections::BTreeMap;

Merge pull request #790 from sharkdp/new-metricsDavid Peterbefore adoptionf26c015

line 2why, one step back
2

Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9

line 3why, one step back
3use serde::Serialize;

Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c

lines 4–7why, one step back
4use 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 back
8use crate::metric::{Metric, MetricSelection, Stats};

Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c

lines 9–11why, one step back
9
10use anyhow::Result;11

Merge pull request #790 from sharkdp/new-metricsDavid Peterbefore adoptionf26c015

lines 12–17why, one step back
12mod 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 back
18struct HyperfineSummary<'a> {

Merge pull request #790 from sharkdp/new-metricsDavid Peterbefore adoptionf26c015

lines 19–20why, one step back
19 schema_version: u32,
20 metadata: &'a Metadata,

Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9

line 21why, one step back
21 primary_metric: &'static str,

Merge pull request #790 from sharkdp/new-metricsDavid Peterbefore adoptionf26c015

line 22why, one step back
22 results: Vec<JsonBenchmarkResult<'a>>,

Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c

lines 23–24why, one step back
23}
24

Merge pull request #790 from sharkdp/new-metricsDavid Peterbefore adoptionf26c015

lines 25–28why, one step back
25#[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 back
29 summary: BTreeMap<&'static str, StatisticalSummary>,

Merge pull request #790 from sharkdp/new-metricsDavid Peterbefore adoptionf26c015

lines 30–33why, one step back
30}
3132#[derive(Serialize)]33struct StatisticalSummary {

Support hardware counters (instructions, cache misses, ...) (#983)David Peterbefore adoptionbc3a3f0

lines 34–35why, one step back
34 #[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 back
36 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 back
45 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 back
58 }

Merge pull request #790 from sharkdp/new-metricsDavid Peterbefore adoptionf26c015

lines 59–61why, one step back
59 }
60}61

Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c

line 62why, one step back
62#[derive(Default)]

Merge pull request #790 from sharkdp/new-metricsDavid Peterbefore adoptionf26c015

lines 63–65why, one step back
63pub struct JsonExporter {
64 metadata: Metadata,65}

Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c

lines 66–67why, one step back
66
67impl Exporter for JsonExporter {

Export selected metrics side by side in CSVDavid Peterbefore adoption067ee70

lines 68–73why, one step back
68 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 back
74 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 back
77 primary_metric: primary.metric.name(),

Merge pull request #790 from sharkdp/new-metricsDavid Peterbefore adoptionf26c015

lines 78–79why, one step back
78 results: results
79 .iter()

Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9

line 80why, one step back
80 .map(|result| JsonBenchmarkResult {

Merge pull request #790 from sharkdp/new-metricsDavid Peterbefore adoptionf26c015

line 81why, one step back
81 result,

Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9

lines 82–90why, one step back
82 summary: Metric::ALL
83 .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 back
91 })
92 .collect(),

Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9

lines 93–95why, one step back
93 })?;
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 back
96 }
97}