-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from tiatomee/lifetimes
Add support for lifetimes in relations
- Loading branch information
Showing
14 changed files
with
582 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use criterion::{black_box, criterion_group, criterion_main, 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) { | ||
c.bench_function_over_inputs( | ||
"fibonacci", | ||
|b, n| { | ||
b.iter(|| fibonacci_length(black_box(*n))); | ||
}, | ||
vec![50, 100, 150], | ||
); | ||
} | ||
|
||
criterion_group!(benches, criterion_benchmark); | ||
criterion_main!(benches); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
use criterion::{black_box, criterion_group, criterion_main, Criterion}; | ||
|
||
use crepe::crepe; | ||
|
||
const MAX_PATH_LEN: u32 = 50; | ||
|
||
crepe! { | ||
@input | ||
struct Edge(i32, i32, u32); | ||
|
||
@output | ||
struct Walk(i32, i32, u32); | ||
|
||
@output | ||
struct NoWalk(i32, i32); | ||
|
||
struct Node(i32); | ||
|
||
Node(x) <- Edge(x, _, _); | ||
Node(x) <- Edge(_, x, _); | ||
|
||
Walk(x, x, 0) <- Node(x); | ||
Walk(x, z, len1 + len2) <- | ||
Edge(x, y, len1), | ||
Walk(y, z, len2), | ||
(len1 + len2 <= MAX_PATH_LEN); | ||
|
||
NoWalk(x, y) <- Node(x), Node(y), !Walk(x, y, _); | ||
} | ||
|
||
fn walk(n: usize) -> (usize, usize) { | ||
let n = n as i32; | ||
let mut edges = Vec::new(); | ||
for i in 0..n { | ||
for j in 0..n { | ||
if i + j % 50 < 2 { | ||
edges.push(Edge(i, j, 5)); | ||
} | ||
} | ||
} | ||
|
||
let mut runtime = Crepe::new(); | ||
runtime.extend(edges); | ||
let (walk, nowalk) = runtime.run_with_hasher::<fnv::FnvBuildHasher>(); | ||
(walk.len(), nowalk.len()) | ||
} | ||
|
||
fn criterion_benchmark(c: &mut Criterion) { | ||
c.bench_function_over_inputs( | ||
"walk", | ||
|b, input| { | ||
b.iter(|| walk(black_box(*input))); | ||
}, | ||
vec![128, 256, 512], | ||
); | ||
} | ||
|
||
criterion_group!(benches, criterion_benchmark); | ||
criterion_main!(benches); |
Oops, something went wrong.