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

fix(lib): adapt to upstream changes #36

Merged
merged 3 commits into from
Nov 19, 2014
Merged
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.0.0"
authors = ["Jorge Aparicio <japaric@linux.com>"]

[dependencies.criterion_macros]
path = "criterion_macros"
path = "macros"

[dependencies.simplot]
git = "https://github.com/japaric/simplot.rs"
Expand Down
2 changes: 1 addition & 1 deletion benches/with_inputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fn from_elem() {

let can_plot = Criterion::default().bench_with_inputs("from_elem", |b, &size| {
b.iter(|| Vec::from_elem(size, 0u8));
}, [KB, 2 * KB, 4 * KB, 8 * KB, 16 * KB]).can_plot();
}, &[KB, 2 * KB, 4 * KB, 8 * KB, 16 * KB]).can_plot();

if can_plot {
// Check that the summary plots have been generated
Expand Down
File renamed without changes.
9 changes: 7 additions & 2 deletions criterion_macros/src/lib.rs → macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ extern crate rustc;
extern crate syntax;

use rustc::plugin::Registry;
use syntax::ast::{DUMMY_NODE_ID, DeclItem, Item, ItemFn, MetaItem, StmtDecl};
use syntax::ast::{DUMMY_NODE_ID, DeclItem, Item, ItemFn, MetaItem, StmtDecl, mod};
use syntax::codemap::{Span, mod};
use syntax::ext::base::{ExtCtxt, Modifier};
use syntax::ext::build::AstBuilder;
Expand Down Expand Up @@ -72,7 +72,12 @@ fn expand_meta_criterion(
let fn_decl = P(codemap::respan(span, DeclItem(routine)));
let inner_fn = P(codemap::respan(span, StmtDecl(fn_decl, DUMMY_NODE_ID)));
let body = cx.block(span, vec!(inner_fn, bench_call), None);
let test = cx.item_fn(span, item.ident, Vec::new(), cx.ty_nil(), body);
let nil = P(ast::Ty {
id: ast::DUMMY_NODE_ID,
node: ast::TyTup(vec![]),
span: codemap::DUMMY_SP,
});
let test = cx.item_fn(span, item.ident, Vec::new(), nil, body);

// Add the `#[test]` attribute to existing attributes
let mut attrs = item.attrs.clone();
Expand Down
8 changes: 5 additions & 3 deletions src/analysis/compare.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
use stats::ttest::{TDistribution, TwoTailed};
use stats::ttest::{TDistribution, Tails};
use stats::{Stats, mod};
use time;

use Criterion;
use estimate::{Distributions, Estimate, Estimates, Mean, Median};
use estimate::Statistic::{Mean, Median};
use estimate::{Distributions, Estimate, Estimates};
use format;
use fs;
use plot;
use report;
use self::ComparisonResult::{Improved, NonSignificant, Regressed};

// Common comparison procedure
pub fn common(
Expand Down Expand Up @@ -67,7 +69,7 @@ fn t_test(id: &str, times: &[f64], base_times: &[f64], criterion: &Criterion) ->
let t_distribution = elapsed!(
"Bootstrapping the T distribution",
TDistribution::new(times, base_times, nresamples));
let p_value = t_distribution.p_value(t_statistic, TwoTailed);
let p_value = t_distribution.p_value(t_statistic, Tails::Two);
let different_mean = p_value < sl;

println!(" > p = {}", p_value);
Expand Down
18 changes: 10 additions & 8 deletions src/analysis/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,8 @@ use estimate::{
Distributions,
Estimate,
Estimates,
Mean,
Median,
MedianAbsDev,
StdDev,
mod,
};
use estimate::Statistic;
use format;
use fs;
use plot;
Expand Down Expand Up @@ -119,8 +115,8 @@ fn common<R: Routine>(id: &str, routine: &mut R, criterion: &Criterion) {
let (distribution, slope) = regression(id, pairs_f64, criterion);
let (mut distributions, mut estimates) = estimates(times, criterion);

estimates.insert(estimate::Slope, slope);
distributions.insert(estimate::Slope, distribution);
estimates.insert(Statistic::Slope, slope);
distributions.insert(Statistic::Slope, distribution);

if criterion.plotting.is_enabled() {
elapsed!(
Expand Down Expand Up @@ -235,7 +231,13 @@ fn estimates(

vec![a, b, c, d]
};
let distributions: Distributions = [Mean, Median, MedianAbsDev, StdDev].iter().map(|&x| {
let statistics = [
Statistic::Mean,
Statistic::Median,
Statistic::MedianAbsDev,
Statistic::StdDev,
];
let distributions: Distributions = statistics.iter().map(|&x| {
x
}).zip(distributions.into_iter()).collect();
let estimates = Estimate::new(&distributions, points[], cl);
Expand Down
10 changes: 5 additions & 5 deletions src/estimate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ pub enum Statistic {
impl Show for Statistic {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
match *self {
Mean => f.pad("mean"),
Median => f.pad("median"),
MedianAbsDev => f.pad("MAD"),
Slope => f.pad("slope"),
StdDev => f.pad("SD"),
Statistic::Mean => f.pad("mean"),
Statistic::Median => f.pad("median"),
Statistic::MedianAbsDev => f.pad("MAD"),
Statistic::Slope => f.pad("slope"),
Statistic::StdDev => f.pad("SD"),
}
}
}
Expand Down
16 changes: 8 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ enum Plotting {
impl Plotting {
fn is_enabled(&self) -> bool {
match *self {
Enabled => true,
Plotting::Enabled => true,
_ => false,
}
}
Expand All @@ -111,11 +111,11 @@ impl Criterion {
#[experimental]
pub fn default() -> Criterion {
let plotting = if simplot::version().is_ok() {
Enabled
Plotting::Enabled
} else {
println!("Gnuplot not found, disabling plotting");

NotAvailable
Plotting::NotAvailable
};

Criterion {
Expand Down Expand Up @@ -255,8 +255,8 @@ impl Criterion {
#[experimental]
pub fn with_plots(&mut self) -> &mut Criterion {
match self.plotting {
NotAvailable => {},
_ => self.plotting = Enabled,
Plotting::NotAvailable => {},
_ => self.plotting = Plotting::Enabled,
}

self
Expand All @@ -266,8 +266,8 @@ impl Criterion {
#[experimental]
pub fn without_plots(&mut self) -> &mut Criterion {
match self.plotting {
NotAvailable => {},
_ => self.plotting = Disabled,
Plotting::NotAvailable => {},
_ => self.plotting = Plotting::Disabled,
}

self
Expand All @@ -276,7 +276,7 @@ impl Criterion {
/// Checks if plotting is possible
pub fn can_plot(&self) -> bool {
match self.plotting {
NotAvailable => false,
Plotting::NotAvailable => false,
_ => true,
}
}
Expand Down
41 changes: 20 additions & 21 deletions src/plot/both.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
use simplot::axis::{BottomX, LeftY, RightY};
use simplot::curve::Lines;
use simplot::grid::Major;
use simplot::key::{Inside, Left, LeftJustified, Outside, Right, SampleText, Top};
use simplot::{Figure, Solid};
use simplot::curve::Style::{Lines};
use simplot::key::{Horizontal, Justification, Order, Position, Vertical};
use simplot::{Axis, Figure, Grid, LineType};
use stats::ConfidenceInterval;
use std::iter::Repeat;
use std::num::Float;
use std::str;
use test::stats::Stats;

use estimate::{Estimate, Estimates, Slope};
use estimate::{Estimate, Estimates};
use estimate::Statistic::Slope;
use kde;
use super::scale_time;
use super::{DARK_BLUE, DARK_RED};
Expand Down Expand Up @@ -82,19 +81,19 @@ pub fn regression(
output(path).
size(PLOT_SIZE).
title(id.to_string()).
axis(BottomX, |a| a.
grid(Major, |g| g.
axis(Axis::BottomX, |a| a.
grid(Grid::Major, |g| g.
show()).
// FIXME (unboxed closures) remove cloning
label(x_label.to_string())).
axis(LeftY, |a| a.
grid(Major, |g| g.
axis(Axis::LeftY, |a| a.
grid(Grid::Major, |g| g.
show()).
label(format!("Total time ({}s)", prefix))).
key(|k| k.
justification(LeftJustified).
order(SampleText).
position(Inside(Top, Left))).
justification(Justification::Left).
order(Order::SampleText).
position(Position::Inside(Vertical::Top, Horizontal::Left))).
filled_curve([0., max_iters].iter(), [0., base_lb].iter(), [0., base_ub].iter(), |c| c.
color(DARK_RED).
opacity(0.25)).
Expand All @@ -104,12 +103,12 @@ pub fn regression(
curve(Lines, [0., max_iters].iter(), [0., base_point].iter(), |c| c.
color(DARK_RED).
label("Base sample").
line_type(Solid).
line_type(LineType::Solid).
linewidth(2.)).
curve(Lines, [0., max_iters].iter(), [0., new_point].iter(), |c| c.
color(DARK_BLUE).
label("New sample").
line_type(Solid).
line_type(LineType::Solid).
linewidth(2.)).
draw().unwrap();

Expand Down Expand Up @@ -137,16 +136,16 @@ pub fn pdfs(base: &[f64], new: &[f64], id: &str) {
output(path).
size(PLOT_SIZE).
title(id.to_string()).
axis(BottomX, |a| a.
axis(Axis::BottomX, |a| a.
label(format!("Average time ({}s)", prefix))).
axis(LeftY, |a| a.
axis(Axis::LeftY, |a| a.
label("Density (a.u.)")).
axis(RightY, |a| a.
axis(Axis::RightY, |a| a.
hide()).
key(|k| k.
justification(LeftJustified).
order(SampleText).
position(Outside(Top, Right))).
justification(Justification::Left).
order(Order::SampleText).
position(Position::Outside(Vertical::Top, Horizontal::Right))).
filled_curve(base_xs, base_ys, zeros, |c| c.
color(DARK_RED).
label("Base PDF").
Expand Down
Loading