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

Do rustfmt on the codebase #619

Closed
wants to merge 2 commits into from
Closed
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
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ jobs:
steps:
- uses: actions/checkout@v2
- uses: dtolnay/rust-toolchain@1.36.0
- run: cargo fmt --all -- --check
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it not be better to add a separate CI target for rustfmt? and why use the MSRV for running the formatting?

something like-

  fmt:
    name: format
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: dtolnay/rust-toolchain@nightly
        with:
          components: rustfmt
      - uses: actions-rs/cargo@v1
        with:
          command: fmt
          args: --all -- --check

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if introducing yet another toolchain is worth here. You can use the stable chain instead, which already exists.

But I'm down for using checkout@3 as well as dtolnay's rust-toolchain.
I have a weird connection with actions-rs, because some of their actions are no longer maintained, but cargo looks good to me, so yeah, that's worth a rewrite in the github workflow.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if introducing yet another toolchain is worth here

in what sense? I would personally split these into separate targets even if they both used the stable toolchain

- run: cargo check --no-default-features
- run: cargo check --no-default-features --features "use_alloc"
- run: cargo check
Expand Down
3 changes: 0 additions & 3 deletions .rustfmt.toml

This file was deleted.

123 changes: 48 additions & 75 deletions benches/bench1.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use itertools::Itertools;
use itertools::free::cloned;
use itertools::iproduct;
use itertools::Itertools;

use std::iter::repeat;
use std::cmp;
use std::iter::repeat;
use std::ops::{Add, Range};

mod extra;
Expand All @@ -15,8 +15,10 @@ fn slice_iter(c: &mut Criterion) {
let xs: Vec<_> = repeat(1i32).take(20).collect();

c.bench_function("slice iter", move |b| {
b.iter(|| for elt in xs.iter() {
black_box(elt);
b.iter(|| {
for elt in xs.iter() {
black_box(elt);
}
})
});
}
Expand All @@ -25,8 +27,10 @@ fn slice_iter_rev(c: &mut Criterion) {
let xs: Vec<_> = repeat(1i32).take(20).collect();

c.bench_function("slice iter rev", move |b| {
b.iter(|| for elt in xs.iter().rev() {
black_box(elt);
b.iter(|| {
for elt in xs.iter().rev() {
black_box(elt);
}
})
});
}
Expand Down Expand Up @@ -307,10 +311,10 @@ fn zip_unchecked_counted_loop(c: &mut Criterion) {
let len = cmp::min(xs.len(), ys.len());
for i in 0..len {
unsafe {
let x = *xs.get_unchecked(i);
let y = *ys.get_unchecked(i);
black_box(x);
black_box(y);
let x = *xs.get_unchecked(i);
let y = *ys.get_unchecked(i);
black_box(x);
black_box(y);
}
}
})
Expand All @@ -329,9 +333,9 @@ fn zipdot_i32_unchecked_counted_loop(c: &mut Criterion) {
let mut s = 0i32;
for i in 0..len {
unsafe {
let x = *xs.get_unchecked(i);
let y = *ys.get_unchecked(i);
s += x * y;
let x = *xs.get_unchecked(i);
let y = *ys.get_unchecked(i);
s += x * y;
}
}
s
Expand All @@ -351,9 +355,9 @@ fn zipdot_f32_unchecked_counted_loop(c: &mut Criterion) {
let mut s = 0f32;
for i in 0..len {
unsafe {
let x = *xs.get_unchecked(i);
let y = *ys.get_unchecked(i);
s += x * y;
let x = *xs.get_unchecked(i);
let y = *ys.get_unchecked(i);
s += x * y;
}
}
s
Expand All @@ -374,12 +378,12 @@ fn zip_unchecked_counted_loop3(c: &mut Criterion) {
let len = cmp::min(xs.len(), cmp::min(ys.len(), zs.len()));
for i in 0..len {
unsafe {
let x = *xs.get_unchecked(i);
let y = *ys.get_unchecked(i);
let z = *zs.get_unchecked(i);
black_box(x);
black_box(y);
black_box(z);
let x = *xs.get_unchecked(i);
let y = *ys.get_unchecked(i);
let z = *zs.get_unchecked(i);
black_box(x);
black_box(y);
black_box(z);
}
}
})
Expand Down Expand Up @@ -464,11 +468,7 @@ fn equal(c: &mut Criterion) {
let alpha = black_box(&data[1..]);
let beta = black_box(&data[..l - 1]);

c.bench_function("equal", move |b| {
b.iter(|| {
itertools::equal(alpha, beta)
})
});
c.bench_function("equal", move |b| b.iter(|| itertools::equal(alpha, beta)));
}

fn merge_default(c: &mut Criterion) {
Expand All @@ -493,9 +493,7 @@ fn merge_default(c: &mut Criterion) {
let data2 = black_box(data2);

c.bench_function("merge default", move |b| {
b.iter(|| {
data1.iter().merge(&data2).count()
})
b.iter(|| data1.iter().merge(&data2).count())
});
}

Expand All @@ -521,9 +519,7 @@ fn merge_by_cmp(c: &mut Criterion) {
let data2 = black_box(data2);

c.bench_function("merge by cmp", move |b| {
b.iter(|| {
data1.iter().merge_by(&data2, PartialOrd::le).count()
})
b.iter(|| data1.iter().merge_by(&data2, PartialOrd::le).count())
});
}

Expand All @@ -549,9 +545,7 @@ fn merge_by_lt(c: &mut Criterion) {
let data2 = black_box(data2);

c.bench_function("merge by lt", move |b| {
b.iter(|| {
data1.iter().merge_by(&data2, |a, b| a <= b).count()
})
b.iter(|| data1.iter().merge_by(&data2, |a, b| a <= b).count())
});
}

Expand All @@ -578,9 +572,7 @@ fn kmerge_default(c: &mut Criterion) {
let its = &[data1.iter(), data2.iter()];

c.bench_function("kmerge default", move |b| {
b.iter(|| {
its.iter().cloned().kmerge().count()
})
b.iter(|| its.iter().cloned().kmerge().count())
});
}

Expand All @@ -603,7 +595,7 @@ fn kmerge_tenway(c: &mut Criterion) {
while rest.len() > 0 {
let chunk_len = 1 + rng(&mut state) % 512;
let chunk_len = cmp::min(rest.len(), chunk_len as usize);
let (fst, tail) = {rest}.split_at_mut(chunk_len);
let (fst, tail) = { rest }.split_at_mut(chunk_len);
fst.sort();
chunks.push(fst.iter().cloned());
rest = tail;
Expand All @@ -612,15 +604,14 @@ fn kmerge_tenway(c: &mut Criterion) {
// println!("Chunk lengths: {}", chunks.iter().format_with(", ", |elt, f| f(&elt.len())));

c.bench_function("kmerge tenway", move |b| {
b.iter(|| {
chunks.iter().cloned().kmerge().count()
})
b.iter(|| chunks.iter().cloned().kmerge().count())
});
}

fn fast_integer_sum<I>(iter: I) -> I::Item
where I: IntoIterator,
I::Item: Default + Add<Output=I::Item>
where
I: IntoIterator,
I::Item: Default + Add<Output = I::Item>,
{
iter.into_iter().fold(<_>::default(), |x, y| x + y)
}
Expand All @@ -629,39 +620,31 @@ fn step_vec_2(c: &mut Criterion) {
let v = vec![0; 1024];

c.bench_function("step vec 2", move |b| {
b.iter(|| {
fast_integer_sum(cloned(v.iter().step_by(2)))
})
b.iter(|| fast_integer_sum(cloned(v.iter().step_by(2))))
});
}

fn step_vec_10(c: &mut Criterion) {
let v = vec![0; 1024];

c.bench_function("step vec 10", move |b| {
b.iter(|| {
fast_integer_sum(cloned(v.iter().step_by(10)))
})
b.iter(|| fast_integer_sum(cloned(v.iter().step_by(10))))
});
}

fn step_range_2(c: &mut Criterion) {
let v = black_box(0..1024);

c.bench_function("step range 2", move |b| {
b.iter(|| {
fast_integer_sum(v.clone().step_by(2))
})
b.iter(|| fast_integer_sum(v.clone().step_by(2)))
});
}

fn step_range_10(c: &mut Criterion) {
let v = black_box(0..1024);

c.bench_function("step range 10", move |b| {
b.iter(|| {
fast_integer_sum(v.clone().step_by(10))
})
b.iter(|| fast_integer_sum(v.clone().step_by(10)))
});
}

Expand Down Expand Up @@ -753,9 +736,7 @@ fn all_equal(c: &mut Criterion) {
let mut xs = vec![0; 5_000_000];
xs.extend(vec![1; 5_000_000]);

c.bench_function("all equal", move |b| {
b.iter(|| xs.iter().all_equal())
});
c.bench_function("all equal", move |b| b.iter(|| xs.iter().all_equal()));
}

fn all_equal_for(c: &mut Criterion) {
Expand Down Expand Up @@ -797,33 +778,25 @@ fn permutations_iter(c: &mut Criterion) {
}

c.bench_function("permutations iter", move |b| {
b.iter(|| {
for _ in NewIterator(0..PERM_COUNT).permutations(PERM_COUNT) {

}
})
b.iter(
|| {
for _ in NewIterator(0..PERM_COUNT).permutations(PERM_COUNT) {}
},
)
});
}

fn permutations_range(c: &mut Criterion) {
c.bench_function("permutations range", move |b| {
b.iter(|| {
for _ in (0..PERM_COUNT).permutations(PERM_COUNT) {

}
})
b.iter(|| for _ in (0..PERM_COUNT).permutations(PERM_COUNT) {})
});
}

fn permutations_slice(c: &mut Criterion) {
let v = (0..PERM_COUNT).collect_vec();

c.bench_function("permutations slice", move |b| {
b.iter(|| {
for _ in v.as_slice().iter().permutations(PERM_COUNT) {

}
})
b.iter(|| for _ in v.as_slice().iter().permutations(PERM_COUNT) {})
});
}

Expand Down
10 changes: 1 addition & 9 deletions benches/combinations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,7 @@ fn comb_c14(c: &mut Criterion) {
}

criterion_group!(
benches,
comb_for1,
comb_for2,
comb_for3,
comb_for4,
comb_c1,
comb_c2,
comb_c3,
comb_c4,
benches, comb_for1, comb_for2, comb_for3, comb_for4, comb_c1, comb_c2, comb_c3, comb_c4,
comb_c14,
);
criterion_main!(benches);
Loading