Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Output format to JSON #10

Open
cecton opened this issue Oct 18, 2023 · 5 comments · May be fixed by #42 or #29
Open

Output format to JSON #10

cecton opened this issue Oct 18, 2023 · 5 comments · May be fixed by #42 or #29
Labels
enhancement New feature or request

Comments

@cecton
Copy link

cecton commented Oct 18, 2023

I'm trying divan at the moment and find it super easy to get started with 🎉

Unfortunately I will need to integrate things into a CI. Normally I should find a way to get the results in a JSON file so I can create a comment on a PR that shows the results. (Example here)

Is it possible to do this with divan?

@cecton
Copy link
Author

cecton commented Oct 18, 2023

oh I just found it in the future plans, nvm

Divan has many opportunities for features. Future versions will have:
Better output options:
Machine-readable output like JSON and CSV.

@nvzqz nvzqz added the enhancement New feature or request label Oct 30, 2023
@Aloso Aloso linked a pull request Nov 12, 2023 that will close this issue
3 tasks
@OliverKillane OliverKillane linked a pull request Jan 17, 2024 that will close this issue
6 tasks
@epage
Copy link

epage commented Feb 8, 2024

For myself, I'm wanting to integrate with bencher.dev which has a json format but also adapters, including for criterion, see https://bencher.dev/docs/explanation/adapters/

Also, as part of rust-lang/rfcs#3558, I want to look into if there is a standard structure we can use for across bench harnesses.

@nvzqz
Copy link
Owner

nvzqz commented Jun 30, 2024

@epage I suspect that each benchmark harness is going to want to run things its own way and thus enforcing a single canonical format across the entire ecosystem might be a futile effort. So rather than enforce a certain schema on the ecosystem, it might be more productive/valuable to enable cargo/rustc hooks that help with information consolidation? Although perhaps this is rhetorical by kicking the can down to the API layer.

@alshdavid
Copy link

alshdavid commented Jul 1, 2024

For me, Divan is by far the best benchmarking tool available in Rust as it allows for benchmarks to be placed in #[cfg(test)] blocks using #[bench] attributes so I really want to use it in all my projects.

Not having access to the benchmark data is currently the only thing preventing me from using Divan in my production projects as we typically run benchmarks in CI and automate adding a "benchmarks" comment to PRs that contain a breakdown, comparison, graphs, etc.

This is pretty easy to track without external tooling, just need the actual run data. I actually tried to parse Divan's stdout at one point 😆

Perhaps a simple unopinionated interim solution would be for divan::main() to return a DivanReport (or add a divan::main_with_report()). That way the output format could be managed by the consumer without prescribing an output format:

#[derive(Serialize)]
pub struct DivanResult {
  pub name: String,
  pub fastest: Duration,
  pub slowest: Duration,
  pub median: Duration,
  pub mean: Duration,
  pub samples: usize,
  pub iters: usize,
}

pub type DivanReport = Vec<DivanResult>;

From here I could obtain it after the run and store it as JSON, CSV, or even generate graphs from Rust directly

// bench.rs
#[cfg(test)]
mod foo_bench;
mod foo;

#[cfg(test)]
fn main() {
  let report = divan::main();
  println!("{}", serde_json::to_string(&report).unwrap());
}

@alshdavid
Copy link

Hi, can we get a progress update on this? 🙏

I'm looking to integrate Divan into my team's project and this is currently the biggest blocker

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
4 participants