-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathfibonacci.rs
40 lines (30 loc) · 960 Bytes
/
fibonacci.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion};
use crepe::crepe;
crepe! {
@input
struct Depth(u128);
@output
struct Fib(u128, u128);
Fib(0, 0) <- (true);
Fib(1, 1) <- (true);
Fib(n + 2, x + y) <-
Depth(depth),
Fib(n, x), Fib(n + 1, y), (n <= depth);
}
// Doesn't return the fibonacci number but instead the number of relations generated.
fn fibonacci_length(n: u128) -> usize {
let mut rt = Crepe::new();
rt.extend([Depth(n)]);
let (fibs,) = rt.run_with_hasher::<fnv::FnvBuildHasher>();
fibs.len()
}
fn criterion_benchmark(c: &mut Criterion) {
let mut group = c.benchmark_group("fibonacci");
for n in [50, 100, 150] {
group.bench_with_input(BenchmarkId::from_parameter(n), &n, |b, &n| {
b.iter(|| fibonacci_length(black_box(n)));
});
}
}
criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);