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

Minimize and speed up the Collatz conjecture bench #20

Merged
merged 1 commit into from
Mar 2, 2022
Merged
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
11 changes: 4 additions & 7 deletions benches/collatz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@ crepe! {
@input
struct Start(u128);
Copy link

Choose a reason for hiding this comment

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

While we're here can you indent this to match the above '@input'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Happy to adjust the indentation, but how exactly? This is the same indentation as in the readme and in the other benchmark, with 4 spaces both before @input and struct 🤔.


struct Intermediate(u128, u128);

@output
struct Col(u128);
Copy link

Choose a reason for hiding this comment

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

Same here


Intermediate(0, n) <- Start(n);
Intermediate(n + 1, if x % 2 == 0 { x / 2 } else { 3 * x + 1 }) <- Intermediate(n, x), (x != 1);

Col(n) <- Intermediate(n, x), (x != 1);
Col(x) <- Start(x);
Col(x / 2) <- Col(x), (x % 2 == 0);
Col(3 * x + 1) <- Col(x), (x % 2 != 0), (x != 1);
}

// Return the stopping time for the given starting number.
Expand All @@ -24,7 +21,7 @@ fn collatz_length(n: u128) -> usize {
rt.extend(&[Start(n)]);

let (cols,) = rt.run_with_hasher::<fnv::FnvBuildHasher>();
cols.len()
cols.len() - 1
}

fn criterion_benchmark(c: &mut Criterion) {
Expand Down