Skip to content

Commit

Permalink
benches: adjust formatting to work on stable, allowing longer lines
Browse files Browse the repository at this point in the history
  • Loading branch information
dhardy committed Nov 27, 2024
1 parent bf21507 commit e57492f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
24 changes: 15 additions & 9 deletions benches/benches/distr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(custom_inner_attributes)]

// Rustfmt splits macro invocations to shorten lines; in this case longer-lines are more readable
#![rustfmt::skip]

use criterion::{criterion_group, criterion_main, Criterion, Throughput};
use criterion_cycles_per_byte::CyclesPerByte;

Expand Down Expand Up @@ -80,7 +75,8 @@ fn bench(c: &mut Criterion<CyclesPerByte>) {
let distr = Normal::new(-E, PI).unwrap();

c.iter(|| {
distr.sample_iter(&mut rng)
distr
.sample_iter(&mut rng)
.take(ITER_ELTS as usize)
.fold(0.0, |a, r| a + r)
});
Expand Down Expand Up @@ -121,12 +117,22 @@ fn bench(c: &mut Criterion<CyclesPerByte>) {
let mut g = c.benchmark_group("weighted");
distr_int!(g, "i8", usize, WeightedIndex::new([1i8, 2, 3, 4, 12, 0, 2, 1]).unwrap());
distr_int!(g, "u32", usize, WeightedIndex::new([1u32, 2, 3, 4, 12, 0, 2, 1]).unwrap());
distr_int!(g, "f64", usize, WeightedIndex::new([1.0f64, 0.001, 1.0/3.0, 4.01, 0.0, 3.3, 22.0, 0.001]).unwrap());
distr_int!(g, "f64", usize, WeightedIndex::new([1.0f64, 0.001, 1.0 / 3.0, 4.01, 0.0, 3.3, 22.0, 0.001]).unwrap());
distr_int!(g, "large_set", usize, WeightedIndex::new((0..10000).rev().chain(1..10001)).unwrap());
distr_int!(g, "alias_method_i8", usize, WeightedAliasIndex::new(vec![1i8, 2, 3, 4, 12, 0, 2, 1]).unwrap());
distr_int!(g, "alias_method_u32", usize, WeightedAliasIndex::new(vec![1u32, 2, 3, 4, 12, 0, 2, 1]).unwrap());
distr_int!(g, "alias_method_f64", usize, WeightedAliasIndex::new(vec![1.0f64, 0.001, 1.0/3.0, 4.01, 0.0, 3.3, 22.0, 0.001]).unwrap());
distr_int!(g, "alias_method_large_set", usize, WeightedAliasIndex::new((0..10000).rev().chain(1..10001).collect()).unwrap());
distr_int!(
g,
"alias_method_f64",
usize,
WeightedAliasIndex::new(vec![1.0f64, 0.001, 1.0 / 3.0, 4.01, 0.0, 3.3, 22.0, 0.001]).unwrap()
);
distr_int!(
g,
"alias_method_large_set",
usize,
WeightedAliasIndex::new((0..10000).rev().chain(1..10001).collect()).unwrap()
);
g.finish();

let mut g = c.benchmark_group("binomial");
Expand Down
4 changes: 1 addition & 3 deletions benches/benches/seq_choose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@ pub fn bench(c: &mut Criterion) {
b.iter(|| {
// Collect full result to prevent unwanted shortcuts getting
// first element (in case sample_indices returns an iterator).
let samples_iter = x
.choose_multiple_weighted(&mut rng, amount, |_| 1.0)
.unwrap();
let samples_iter = x.choose_multiple_weighted(&mut rng, amount, |_| 1.0).unwrap();
for (slot, sample) in y.iter_mut().zip(samples_iter) {
*slot = *sample;
}
Expand Down
2 changes: 2 additions & 0 deletions benches/rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
max_width = 120
fn_call_width = 108

0 comments on commit e57492f

Please sign in to comment.