aboutsummaryrefslogtreecommitdiffstats
path: root/benches
diff options
context:
space:
mode:
authorEdvard Thörnros <edvard.thornros@gmail.com>2021-02-19 18:07:21 +0100
committerGitHub <noreply@github.com>2021-02-19 18:07:21 +0100
commitfe41db5dceecb01a0ada18ea2fc369abb1498aa3 (patch)
tree539e63178a3a687bc4df92d53712cd9b028bf0e9 /benches
parentf024e88de53c24fd5e5e2fb2d66947dc93262af8 (diff)
parent7e330b8d622183696ddf3c7f8140c6510804e0a0 (diff)
downloadsylt-fe41db5dceecb01a0ada18ea2fc369abb1498aa3.tar.gz
Merge branch 'main' into unusued-variables
Diffstat (limited to 'benches')
-rw-r--r--benches/sylt_benchmark.rs56
1 files changed, 22 insertions, 34 deletions
diff --git a/benches/sylt_benchmark.rs b/benches/sylt_benchmark.rs
index a68a762..e77a916 100644
--- a/benches/sylt_benchmark.rs
+++ b/benches/sylt_benchmark.rs
@@ -1,42 +1,30 @@
use criterion::{criterion_group, criterion_main, Criterion};
+use std::fs;
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 = sylt::compiler::compile("main", Path::new("prog"), sylt::tokenizer::string_to_tokens(prog)).unwrap();
- c.bench_function("fib 50", |b| b.iter(|| sylt::vm::run_block(&compiled).unwrap()));
+macro_rules! bench_file {
+ ( $name:ident ) => {
+ pub fn $name(c: &mut Criterion) {
+ let prog = fs::read_to_string(Path::new(&format!("progs/bench/{}.sy", stringify!($name))))
+ .unwrap();
+ c.bench_function(stringify!($name), |b| {
+ b.iter(|| {
+ sylt::run_string(&prog, false, Vec::new()).unwrap();
+ })
+ });
+ }
+ };
}
-pub fn fib_90(c: &mut Criterion) {
- let prog =
-"
-a := 0
-b := 1
+macro_rules! bench {
+ ( [ $( $name:ident ),* ] ) => {
+ $(bench_file!($name);)*
-for i := 0, i < 90, i = i + 1 {
- c := a
- a = b
- b = c + b
-}
-a <=> 2880067194370816120
-";
- let compiled = sylt::compiler::compile("main", Path::new("prog"), sylt::tokenizer::string_to_tokens(prog)).unwrap();
- c.bench_function("fib 90", |b| b.iter(|| sylt::vm::run_block(&compiled).unwrap()));
+ criterion_group!(benches, $( $name ),* );
+ criterion_main!(benches);
+ }
}
-criterion_group!(benches, fib_50, fib_90);
-criterion_main!(benches);
+// List of all benchmarks to run
+bench!([fib, fib_iter, sum]);
+