Skip to content

Commit

Permalink
feat!: remove all plotting related functionalities (#27)
Browse files Browse the repository at this point in the history
I don't need them, and they make everything too complicated
  • Loading branch information
Boshen authored Jun 1, 2024
1 parent 0ad7d78 commit 44808ed
Show file tree
Hide file tree
Showing 47 changed files with 17 additions and 7,308 deletions.
29 changes: 0 additions & 29 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 1 addition & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@ tokio = { version = "1.37", default-features = false, features = [
"rt",
], optional = true }
async-std = { version = "1.12", optional = true }
plotters = { version = "^0.3.5", default-features = false, features = [
"svg_backend",
"area_series",
"line_series",
], optional = true }
codspeed = { version = "2.6.0", optional = true }
colored = { version = "2.1.0", optional = true }

Expand All @@ -80,7 +75,7 @@ stable = [
"async_tokio",
"async_std",
]
default = ["rayon", "plotters", "cargo_bench_support"]
default = ["rayon", "cargo_bench_support"]

## Enables [codspeed](https://codspeed.io)
codspeed = ["dep:codspeed", "dep:colored"]
Expand Down
1 change: 0 additions & 1 deletion src/analysis/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ pub(crate) fn common<M: Measurement, T: ?Sized>(
id: id.into(),
iters: &iters,
times: &times,
plot_config: (&report_context.plot_config).into(),
sampling_method: sampling_mode.into(),
benchmark_config: config.into(),
})
Expand Down
3 changes: 1 addition & 2 deletions src/benchmark.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{PlotConfiguration, SamplingMode};
use crate::SamplingMode;
use std::time::Duration;

// TODO: Move the benchmark config stuff to a separate module for easier use.
Expand Down Expand Up @@ -44,7 +44,6 @@ pub(crate) struct PartialBenchmarkConfig {
pub(crate) warm_up_time: Option<Duration>,
pub(crate) sampling_mode: Option<SamplingMode>,
pub(crate) quick_mode: Option<bool>,
pub(crate) plot_config: PlotConfiguration,
}

impl PartialBenchmarkConfig {
Expand Down
20 changes: 5 additions & 15 deletions src/benchmark_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::report::BenchmarkId as InternalBenchmarkId;
use crate::report::Report;
use crate::report::ReportContext;
use crate::routine::{Function, Routine};
use crate::{Mode, PlotConfiguration, SamplingMode, Throughput};
use crate::{Mode, SamplingMode, Throughput};

/// Structure used to group together a set of related benchmarks, along with custom configuration
/// settings for groups of benchmarks. All benchmarks performed using a benchmark group will be
Expand Down Expand Up @@ -218,12 +218,6 @@ impl<'a, M: Measurement> BenchmarkGroup<'a, M> {
self
}

/// Changes the plot configuration for this benchmark group.
pub fn plot_config(&mut self, new_config: PlotConfiguration) -> &mut Self {
self.partial_config.plot_config = new_config;
self
}

/// Set the input size for this benchmark group. Used for reporting the
/// throughput.
pub fn throughput(&mut self, throughput: Throughput) -> &mut Self {
Expand Down Expand Up @@ -278,10 +272,8 @@ impl<'a, M: Measurement> BenchmarkGroup<'a, M> {
I: ?Sized,
{
let config = self.partial_config.to_complete(&self.criterion.config);
let report_context = ReportContext {
output_directory: self.criterion.output_directory.clone(),
plot_config: self.partial_config.plot_config.clone(),
};
let report_context =
ReportContext { output_directory: self.criterion.output_directory.clone() };

let mut id = InternalBenchmarkId::new(
self.group_name.clone(),
Expand Down Expand Up @@ -378,10 +370,8 @@ impl<'a, M: Measurement> Drop for BenchmarkGroup<'a, M> {
}

if self.all_ids.len() > 1 && self.any_matched && self.criterion.mode.is_benchmark() {
let report_context = ReportContext {
output_directory: self.criterion.output_directory.clone(),
plot_config: self.partial_config.plot_config.clone(),
};
let report_context =
ReportContext { output_directory: self.criterion.output_directory.clone() };

self.criterion.report.summarize(
&report_context,
Expand Down
11 changes: 1 addition & 10 deletions src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{report::CliVerbosity, BenchmarkConfig, ListFormat, PlottingBackend};
use crate::{report::CliVerbosity, BenchmarkConfig, ListFormat};
use bpaf::*;
use std::{str::FromStr, time::Duration};

Expand All @@ -20,7 +20,6 @@ pub struct Opts {
pub noise_threshold: f64,
pub confidence_level: f64,
pub significance_level: f64,
pub plotting_backend: Option<PlottingBackend>,
pub output_format: OutputFormat,

// ignored
Expand Down Expand Up @@ -274,13 +273,6 @@ pub fn options(config: &BenchmarkConfig) -> OptionParser<Opts> {
.help("Ignored, but added for compatibility with libsets.")
.switch()
.hide();
let plotting_backend = long("plotting-backend")
.help(
"Set the plotting backend. By default, Criterion.rs will use the gnuplot backend \
if gnuplot is available, or the plotters backend if it isn't.",
)
.argument("PLOT")
.optional();

let output_format =
long("output-format")
Expand All @@ -294,7 +286,6 @@ pub fn options(config: &BenchmarkConfig) -> OptionParser<Opts> {
warm_up_time, measurement_time,
nresamples, noise_threshold, confidence_level, significance_level,
nocapture, show_output, include_ignored,
plotting_backend,
output_format,
ignored, exact, filter})
.to_options()
Expand Down
5 changes: 1 addition & 4 deletions src/codspeed/benchmark_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::{cell::RefCell, rc::Rc, time::Duration};
use codspeed::{codspeed::CodSpeed, utils::get_git_relative_path};

use crate::measurement::WallTime;
use crate::{measurement::Measurement, PlotConfiguration, SamplingMode, Throughput};
use crate::{measurement::Measurement, SamplingMode, Throughput};

use super::bencher::Bencher;
use super::criterion::Criterion;
Expand Down Expand Up @@ -109,9 +109,6 @@ impl<'a, M: Measurement> BenchmarkGroup<'a, M> {
pub fn sampling_mode(&mut self, new_mode: SamplingMode) -> &mut Self {
self
}
pub fn plot_config(&mut self, new_config: PlotConfiguration) -> &mut Self {
self
}
pub fn finish(self) {}
}

Expand Down
13 changes: 0 additions & 13 deletions src/codspeed/criterion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use std::{cell::RefCell, marker::PhantomData, rc::Rc, time::Duration};
use crate::{
measurement::{Measurement, WallTime},
profiler::Profiler,
PlottingBackend,
};
use codspeed::codspeed::CodSpeed;

Expand Down Expand Up @@ -106,9 +105,6 @@ impl<M: Measurement> Criterion<M> {
pub fn with_profiler<P: Profiler + 'static>(self, p: P) -> Criterion<M> {
self
}
pub fn plotting_backend(mut self, backend: PlottingBackend) -> Criterion<M> {
self
}
pub fn sample_size(mut self, n: usize) -> Criterion<M> {
self
}
Expand All @@ -130,15 +126,6 @@ impl<M: Measurement> Criterion<M> {
pub fn significance_level(mut self, sl: f64) -> Criterion<M> {
self
}
pub fn with_plots(mut self) -> Criterion<M> {
self
}
pub fn without_plots(mut self) -> Criterion<M> {
self
}
pub fn can_plot(&self) -> bool {
true
}
pub fn save_baseline(mut self, baseline: String) -> Criterion<M> {
self
}
Expand Down
7 changes: 0 additions & 7 deletions src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,6 @@ pub enum OutgoingMessage<'a> {
id: RawBenchmarkId,
iters: &'a [f64],
times: &'a [f64],
plot_config: PlotConfiguration,
sampling_method: SamplingMethod,
benchmark_config: BenchmarkConfig,
},
Expand Down Expand Up @@ -288,12 +287,6 @@ impl From<crate::AxisScale> for AxisScale {
pub struct PlotConfiguration {
summary_scale: AxisScale,
}
impl From<&crate::PlotConfiguration> for PlotConfiguration {
fn from(other: &crate::PlotConfiguration) -> Self {
PlotConfiguration { summary_scale: other.summary_scale.into() }
}
}

#[derive(Debug, Serialize)]
struct Duration {
secs: u64,
Expand Down
70 changes: 4 additions & 66 deletions src/criterion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ use std::time::Duration;
use crate::bencher::Bencher;
use crate::benchmark_group::{BenchmarkGroup, BenchmarkId};
use crate::{
cargo_criterion_connection, debug_enabled, default_output_directory, default_plotting_backend,
gnuplot_version, Baseline, BencherReport, BenchmarkConfig, BenchmarkFilter, CliReport,
CliVerbosity, Connection, ExternalProfiler, Html, Measurement, Mode, OutgoingMessage,
PlotConfiguration, PlottingBackend, Profiler, Report, ReportContext, Reports, WallTime,
cargo_criterion_connection, debug_enabled, default_output_directory, Baseline, BencherReport,
BenchmarkConfig, BenchmarkFilter, CliReport, CliVerbosity, Connection, ExternalProfiler,
Measurement, Mode, OutgoingMessage, Profiler, Report, ReportContext, Reports, WallTime,
};

/// The benchmark manager
Expand Down Expand Up @@ -62,7 +61,6 @@ impl Default for Criterion {
cli: CliReport::new(false, false, CliVerbosity::Normal),
bencher_enabled: false,
bencher: BencherReport,
html: default_plotting_backend().create_plotter().map(Html::new),
csv_enabled: cfg!(feature = "csv_output"),
};

Expand All @@ -87,7 +85,6 @@ impl Default for Criterion {
criterion.report.cli_enabled = false;
criterion.report.bencher_enabled = false;
criterion.report.csv_enabled = false;
criterion.report.html = None;
}
criterion
}
Expand Down Expand Up @@ -122,25 +119,6 @@ impl<M: Measurement> Criterion<M> {
Criterion { profiler: Box::new(RefCell::new(p)), ..self }
}

#[must_use]
/// Set the plotting backend. By default, Criterion will use gnuplot if available, or plotters
/// if not.
///
/// Panics if `backend` is `PlottingBackend::Gnuplot` and gnuplot is not available.
pub fn plotting_backend(mut self, backend: PlottingBackend) -> Criterion<M> {
if let PlottingBackend::Gnuplot = backend {
assert!(
!gnuplot_version().is_err(),
"Gnuplot plotting backend was requested, but gnuplot is not available. \
To continue, either install Gnuplot or allow Criterion.rs to fall back \
to using plotters."
);
}

self.report.html = backend.create_plotter().map(Html::new);
self
}

#[must_use]
/// Changes the default size of the sample for benchmarks run with this runner.
///
Expand Down Expand Up @@ -279,28 +257,6 @@ impl<M: Measurement> Criterion<M> {
self
}

#[must_use]
/// Enables plotting
pub fn with_plots(mut self) -> Criterion<M> {
// If running under cargo-criterion then don't re-enable the reports; let it do the reporting.
if self.connection.is_none() && self.report.html.is_none() {
let default_backend = default_plotting_backend().create_plotter();
if let Some(backend) = default_backend {
self.report.html = Some(Html::new(backend));
} else {
panic!("Cannot find a default plotting backend!");
}
}
self
}

#[must_use]
/// Disables plotting
pub fn without_plots(mut self) -> Criterion<M> {
self.report.html = None;
self
}

#[must_use]
/// Names an explicit baseline and enables overwriting the previous results.
pub fn save_baseline(mut self, baseline: String) -> Criterion<M> {
Expand Down Expand Up @@ -362,10 +318,7 @@ impl<M: Measurement> Criterion<M> {
return;
}

let report_context = ReportContext {
output_directory: self.output_directory.clone(),
plot_config: PlotConfiguration::default(),
};
let report_context = ReportContext { output_directory: self.output_directory.clone() };

self.report.final_summary(&report_context);
}
Expand All @@ -387,12 +340,6 @@ impl<M: Measurement> Criterion<M> {
if opts.verbosity == CliVerbosity::Verbose {
eprintln!("Warning: --verbose will be ignored when running with cargo-criterion. Use `cargo criterion --output-format verbose -- <args>` instead.");
}
if opts.noplot {
eprintln!("Warning: --noplot will be ignored when running with cargo-criterion. Use `cargo criterion --plotting-backend disabled -- <args>` instead.");
}
if let Some(backend) = opts.plotting_backend {
eprintln!("Warning: --plotting-backend will be ignored when running with cargo-criterion. Use `cargo criterion --plotting-backend {} -- <args>` instead.", backend);
}
if opts.output_format != OutputFormat::Criterion {
eprintln!("Warning: --output-format will be ignored when running with cargo-criterion. Use `cargo criterion --output-format {} -- <args>` instead.", opts.output_format);
}
Expand Down Expand Up @@ -432,14 +379,6 @@ impl<M: Measurement> Criterion<M> {
};
self = self.with_benchmark_filter(filter);

if let Some(backend) = opts.plotting_backend {
self = self.plotting_backend(backend)
};

if opts.noplot {
self = self.without_plots();
}

match opts.baseline {
Baseline_::Save(ref dir) => {
self.baseline = Baseline::Save;
Expand All @@ -463,7 +402,6 @@ impl<M: Measurement> Criterion<M> {
self.report.cli_enabled = false;
self.report.bencher_enabled = false;
self.report.csv_enabled = false;
self.report.html = None;
} else {
match opts.output_format {
OutputFormat::Bencher => {
Expand Down
Loading

0 comments on commit 44808ed

Please sign in to comment.