diff options
| author | Gustav Sörnäs <gustav@sornas.net> | 2021-01-12 23:36:36 +0100 |
|---|---|---|
| committer | Gustav Sörnäs <gustav@sornas.net> | 2021-01-12 23:36:36 +0100 |
| commit | 5492b85a79807dab301ab5f040504bf2538ffaf7 (patch) | |
| tree | e7e1dd0e016c4d049a4478c937c77467acf21e45 /benches | |
| parent | 4db5a471562130947830ad3edc127a7a994f8e7d (diff) | |
| download | sylt-5492b85a79807dab301ab5f040504bf2538ffaf7.tar.gz | |
add optional benchmarks
Run with cargo bench --features=criterion
Diffstat (limited to 'benches')
| -rw-r--r-- | benches/tihdy_benchmark.rs | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/benches/tihdy_benchmark.rs b/benches/tihdy_benchmark.rs new file mode 100644 index 0000000..f639fb0 --- /dev/null +++ b/benches/tihdy_benchmark.rs @@ -0,0 +1,42 @@ +use criterion::{criterion_group, criterion_main, Criterion}; +use std::path::Path; + +pub fn fib_50(c: &mut Criterion) { + let prog = +" +j := 0 +for , j < 1000, j = j + 1 { + a := 0 + b := 1 + + for i := 0, i < 50, i = i + 1 { + c := a + a = b + b = c + b + } + a <=> 12586269025 +} +"; + let compiled = tihdy::compiler::compile("main", Path::new("prog"), tihdy::tokenizer::string_to_tokens(prog)).unwrap(); + c.bench_function("fib 50", |b| b.iter(|| tihdy::vm::run_block(&compiled).unwrap())); +} + +pub fn fib_90(c: &mut Criterion) { + let prog = +" +a := 0 +b := 1 + +for i := 0, i < 90, i = i + 1 { + c := a + a = b + b = c + b +} +a <=> 2880067194370816120 +"; + let compiled = tihdy::compiler::compile("main", Path::new("prog"), tihdy::tokenizer::string_to_tokens(prog)).unwrap(); + c.bench_function("fib 90", |b| b.iter(|| tihdy::vm::run_block(&compiled).unwrap())); +} + +criterion_group!(benches, fib_50, fib_90); +criterion_main!(benches); |
