Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [0.8.2](https://github.com/criterion-rs/criterion.rs/compare/criterion-v0.8.1...criterion-v0.8.2) - 2026-02-04

### Changed

- Added support for plots with logarithmic axis with base other than 10 (e.g. log2)
Comment on lines +12 to +14

### Fixed

- don't build alloca on unsupported targets
Expand Down
2 changes: 1 addition & 1 deletion book/src/user_guide/advanced_configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ fn do_a_thing(x: u64) {

fn bench(c: &mut Criterion) {
let plot_config = PlotConfiguration::default()
.summary_scale(AxisScale::Logarithmic);
.summary_scale(AxisScale::Logarithmic(10.0));

let mut group = c.benchmark_group("log_scale_example");
group.plot_config(plot_config);
Expand Down
13 changes: 5 additions & 8 deletions plot/src/axis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub struct Properties {
grids: map::grid::Map<grid::Properties>,
hidden: bool,
label: Option<Cow<'static, str>>,
logarithmic: bool,
scale: Scale,
range: Option<(f64, f64)>,
scale_factor: f64,
tics: Option<String>,
Expand All @@ -26,7 +26,7 @@ impl Default for Properties {
grids: map::grid::Map::new(),
hidden: false,
label: None,
logarithmic: false,
scale: Scale::Linear,
range: None,
scale_factor: 1.,
tics: None,
Expand Down Expand Up @@ -103,10 +103,7 @@ impl Set<Scale> for Properties {
fn set(&mut self, scale: Scale) -> &mut Properties {
self.hidden = false;

match scale {
Scale::Linear => self.logarithmic = false,
Scale::Logarithmic => self.logarithmic = true,
}
self.scale = scale;

self
}
Expand Down Expand Up @@ -178,8 +175,8 @@ impl Script for (Axis, &Properties) {
script.push_str(&format!("set {}range [{}:{}]\n", axis_, low, high))
}

if properties.logarithmic {
script.push_str(&format!("set logscale {}\n", axis_));
if let Scale::Logarithmic(base) = properties.scale {
script.push_str(&format!("set logscale {} {}\n", axis_, base))
}
Comment on lines 175 to 180

for (grid, properties) in properties.grids.iter() {
Expand Down
2 changes: 1 addition & 1 deletion plot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,7 @@ pub enum PointType {
#[derive(Clone, Copy)]
pub enum Scale {
Linear,
Logarithmic,
Logarithmic(f64),
}

/// Axis scale factor
Expand Down
4 changes: 2 additions & 2 deletions src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,13 +308,13 @@ impl From<&InternalBenchmarkId> for RawBenchmarkId {
#[derive(Debug, Serialize)]
pub enum AxisScale {
Linear,
Logarithmic,
LogarithmicWithBase(f64),
}
impl From<crate::AxisScale> for AxisScale {
fn from(other: crate::AxisScale) -> Self {
match other {
crate::AxisScale::Linear => AxisScale::Linear,
crate::AxisScale::Logarithmic => AxisScale::Logarithmic,
crate::AxisScale::Logarithmic(base) => AxisScale::LogarithmicWithBase(base),
}
Comment on lines 308 to 318
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1323,8 +1323,8 @@ pub enum AxisScale {
#[default]
Linear,

/// Axes scale logarithmically
Logarithmic,
/// Axes scale logarithmically, with specified base
Logarithmic(f64),
}
Comment on lines 1323 to 1328

/// Contains the configuration options for the plots generated by a particular benchmark
Expand All @@ -1334,7 +1334,7 @@ pub enum AxisScale {
/// use self::criterion::{Bencher, Criterion, PlotConfiguration, AxisScale};
///
/// let plot_config = PlotConfiguration::default()
/// .summary_scale(AxisScale::Logarithmic);
/// .summary_scale(AxisScale::Logarithmic(10.0));
///
/// // Using Criterion::default() for simplicity; normally you'd use the macros.
/// let mut criterion = Criterion::default();
Expand Down
15 changes: 3 additions & 12 deletions src/plot/gnuplot_backend/summary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,6 @@ static COMPARISON_COLORS: [Color; NUM_COLORS] = [
Color::Rgb(0, 255, 127),
];

impl AxisScale {
fn to_gnuplot(self) -> Scale {
match self {
AxisScale::Linear => Scale::Linear,
AxisScale::Logarithmic => Scale::Logarithmic,
}
}
}

#[allow(clippy::explicit_counter_loop)]
pub(crate) fn line_comparison(
line_cfg: LinePlotConfig,
Expand Down Expand Up @@ -71,7 +62,7 @@ pub(crate) fn line_comparison(
.set(Title(format!("{}: Comparison", gnuplot_escape(title))))
.configure(Axis::BottomX, |a| {
a.set(Label(format!("Input{}", input_suffix)))
.set(axis_scale.to_gnuplot())
.set(Scale::from(axis_scale))
});

let mut i = 0;
Expand All @@ -92,7 +83,7 @@ pub(crate) fn line_comparison(
a.configure(Grid::Major, |g| g.show())
.configure(Grid::Minor, |g| g.hide())
.set(Label(format!("Average {} ({})", line_cfg.label, unit)))
.set(axis_scale.to_gnuplot())
.set(Scale::from(axis_scale))
});

// This assumes the curves are sorted. It also assumes that the benchmark IDs all have numeric
Expand Down Expand Up @@ -189,7 +180,7 @@ pub fn violin(
.configure(Grid::Minor, |g| g.hide())
.set(Range::Limits(0., max * one[0]))
.set(Label(format!("Average time ({})", unit)))
.set(axis_scale.to_gnuplot())
.set(Scale::from(axis_scale))
})
.configure(Axis::LeftY, |a| {
a.set(Label("Input"))
Expand Down
12 changes: 12 additions & 0 deletions src/plot/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ mod gnuplot_backend;
#[cfg(feature = "plotters")]
mod plotters_backend;

use criterion_plot::Scale;
pub(crate) use gnuplot_backend::Gnuplot;
#[cfg(feature = "plotters")]
pub(crate) use plotters_backend::PlottersBackend;

use crate::AxisScale;

use {
crate::{
estimate::Statistic,
Expand Down Expand Up @@ -34,6 +37,15 @@ pub(crate) struct PlotContext<'a> {
pub(crate) is_thumbnail: bool,
}

impl From<AxisScale> for Scale {
fn from(value: AxisScale) -> Self {
match value {
AxisScale::Linear => Scale::Linear,
AxisScale::Logarithmic(base) => Scale::Logarithmic(base),
}
Comment on lines +40 to +45
}
}

impl<'a> PlotContext<'a> {
pub fn size(mut self, s: Option<criterion_plot::Size>) -> PlotContext<'a> {
if let Some(s) = s {
Expand Down
25 changes: 16 additions & 9 deletions src/plot/plotters_backend/summary.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use {
super::*,
crate::AxisScale,
criterion_plot::Scale,
itertools::Itertools,
plotters::coord::{
ranged1d::{AsRangedCoord, ValueFormatter as PlottersValueFormatter},
Expand Down Expand Up @@ -41,8 +42,8 @@ pub(crate) fn line_comparison(
.titled(&format!("{}: Comparison", title), (DEFAULT_FONT, 20))
.unwrap();

match axis_scale {
AxisScale::Linear => draw_line_comparison_figure(
match Scale::from(axis_scale) {
Scale::Linear => draw_line_comparison_figure(
line_cfg,
root_area,
unit,
Expand All @@ -51,12 +52,12 @@ pub(crate) fn line_comparison(
value_type,
series_data,
),
AxisScale::Logarithmic => draw_line_comparison_figure(
Scale::Logarithmic(base) => draw_line_comparison_figure(
line_cfg,
root_area,
unit,
x_range.log_scale(),
y_range.log_scale(),
x_range.log_scale().base(base),
y_range.log_scale().base(base),
value_type,
series_data,
),
Expand Down Expand Up @@ -223,10 +224,16 @@ pub fn violin(
.titled(&format!("{}: Violin plot", title), (DEFAULT_FONT, 20))
.unwrap();

match axis_scale {
AxisScale::Linear => draw_violin_figure(root_area, unit, x_range, y_range, kdes),
AxisScale::Logarithmic => {
draw_violin_figure(root_area, unit, x_range.log_scale(), y_range, kdes);
match Scale::from(axis_scale) {
Scale::Linear => draw_violin_figure(root_area, unit, x_range, y_range, kdes),
Scale::Logarithmic(base) => {
draw_violin_figure(
root_area,
unit,
x_range.log_scale().base(base),
y_range,
kdes,
);
}
}
}
Expand Down