Skip to content

Commit

Permalink
Start playing around with some benchmarking
Browse files Browse the repository at this point in the history
Trying criterion, not sure if I like it for this use case
  • Loading branch information
rctcwyvrn committed Aug 21, 2020
1 parent 8d437a3 commit 89bf7a5
Show file tree
Hide file tree
Showing 17 changed files with 1,537 additions and 134 deletions.
604 changes: 604 additions & 0 deletions Cargo.lock

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,8 @@ path = "src/lib.rs"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
criterion = "*"

[[bench]]
name = "benches"
harness = false
51 changes: 51 additions & 0 deletions benches/benches.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use rlox::interpret;
use std::fs;

fn binary_trees(c: &mut Criterion) {
let code = fs::read_to_string("test/benchmark_v2/binary_trees.lox").unwrap();
c.bench_function("binary_trees", |b| b.iter(|| interpret(black_box(&code), false, false)));
}

fn equality(c: &mut Criterion) {
let code = fs::read_to_string("test/benchmark_v2/equality.lox").unwrap();
c.bench_function("equality", |b| b.iter(|| interpret(black_box(&code), false, false)));
}

fn fib(c: &mut Criterion) {
let code = fs::read_to_string("test/benchmark_v2/fib.lox").unwrap();
c.bench_function("fib", |b| b.iter(|| interpret(black_box(&code), false, false)));
}

fn instantiation(c: &mut Criterion) {
let code = fs::read_to_string("test/benchmark_v2/instantiation.lox").unwrap();
c.bench_function("instantiation", |b| b.iter(|| interpret(black_box(&code), false, false)));
}

fn method_call(c: &mut Criterion) {
let code = fs::read_to_string("test/benchmark_v2/method_call.lox").unwrap();
c.bench_function("method_call", |b| b.iter(|| interpret(black_box(&code), false, false)));
}

fn properties(c: &mut Criterion) {
let code = fs::read_to_string("test/benchmark_v2/properties.lox").unwrap();
c.bench_function("properties", |b| b.iter(|| interpret(black_box(&code), false, false)));
}

fn string_equality(c: &mut Criterion) {
let code = fs::read_to_string("test/benchmark_v2/string_equality.lox").unwrap();
c.bench_function("string_equality", |b| b.iter(|| interpret(black_box(&code), false, false)));
}

fn trees(c: &mut Criterion) {
let code = fs::read_to_string("test/benchmark_v2/trees.lox").unwrap();
c.bench_function("trees", |b| b.iter(|| interpret(black_box(&code), false, false)));
}

fn zoo(c: &mut Criterion) {
let code = fs::read_to_string("test/benchmark_v2/zoo.lox").unwrap();
c.bench_function("zoo", |b| b.iter(|| interpret(black_box(&code), false, false)));
}

criterion_group!(benches, binary_trees, equality, fib, instantiation, method_call, properties, string_equality, trees, zoo);
criterion_main!(benches);
Loading

0 comments on commit 89bf7a5

Please sign in to comment.