-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
614 additions
and
22 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,101 @@ | ||
use criterion::{criterion_group, criterion_main, Criterion}; | ||
use reblessive::{Stack, Stk}; | ||
|
||
async fn heavy_fibbo(ctx: &mut Stk, n: usize) -> usize { | ||
match n { | ||
0 => 1, | ||
1 => 1, | ||
x => { | ||
ctx.run(move |ctx| heavy_fibbo(ctx, x - 1)).await | ||
+ ctx.run(move |ctx| heavy_fibbo(ctx, x - 2)).await | ||
} | ||
} | ||
} | ||
|
||
fn bench_fibbo(c: &mut Criterion) { | ||
c.bench_function("fib 15", |b| { | ||
b.iter(|| { | ||
// Create a stack to run the function in. | ||
let mut stack = Stack::new(); | ||
|
||
// run the function to completion on the stack. | ||
let res = stack.enter(|ctx| heavy_fibbo(ctx, 15)).finish(); | ||
assert_eq!(res, 987); | ||
}) | ||
}); | ||
|
||
c.bench_function("fib 20", |b| { | ||
b.iter(|| { | ||
// Create a stack to run the function in. | ||
let mut stack = Stack::new(); | ||
|
||
// run the function to completion on the stack. | ||
let res = stack.enter(|ctx| heavy_fibbo(ctx, 20)).finish(); | ||
assert_eq!(res, 10946); | ||
}) | ||
}); | ||
|
||
c.bench_function("fib 25", |b| { | ||
b.iter(|| { | ||
// Create a stack to run the function in. | ||
let mut stack = Stack::new(); | ||
|
||
// run the function to completion on the stack. | ||
let res = stack.enter(|ctx| heavy_fibbo(ctx, 30)).finish(); | ||
assert_eq!(res, 1346269); | ||
}) | ||
}); | ||
} | ||
|
||
fn bench_fibbo_async(c: &mut Criterion) { | ||
c.bench_function("fib async 15", |b| { | ||
let rt = tokio::runtime::Builder::new_current_thread() | ||
.build() | ||
.unwrap(); | ||
b.iter(|| { | ||
rt.block_on(async { | ||
// Create a stack to run the function in. | ||
let mut stack = Stack::new(); | ||
|
||
// run the function to completion on the stack. | ||
let res = stack.enter(|ctx| heavy_fibbo(ctx, 15)).finish_async().await; | ||
assert_eq!(res, 987); | ||
}) | ||
}) | ||
}); | ||
|
||
c.bench_function("fib async 20", |b| { | ||
let rt = tokio::runtime::Builder::new_current_thread() | ||
.build() | ||
.unwrap(); | ||
b.iter(|| { | ||
rt.block_on(async { | ||
// Create a stack to run the function in. | ||
let mut stack = Stack::new(); | ||
|
||
// run the function to completion on the stack. | ||
let res = stack.enter(|ctx| heavy_fibbo(ctx, 20)).finish_async().await; | ||
assert_eq!(res, 10946); | ||
}) | ||
}) | ||
}); | ||
|
||
c.bench_function("fib async 25", |b| { | ||
let rt = tokio::runtime::Builder::new_current_thread() | ||
.build() | ||
.unwrap(); | ||
b.iter(|| { | ||
rt.block_on(async { | ||
// Create a stack to run the function in. | ||
let mut stack = Stack::new(); | ||
|
||
// run the function to completion on the stack. | ||
let res = stack.enter(|ctx| heavy_fibbo(ctx, 30)).finish_async().await; | ||
assert_eq!(res, 1346269); | ||
}) | ||
}) | ||
}); | ||
} | ||
|
||
criterion_group!(benches, bench_fibbo, bench_fibbo_async); | ||
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
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