Skip to content

Commit

Permalink
Remove iteration benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
schungx committed May 16, 2024
1 parent eac9d32 commit 598966a
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 71 deletions.
24 changes: 12 additions & 12 deletions benches/eval_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,23 +62,23 @@ fn bench_type_method(bench: &mut Bencher) {
bench.iter(|| engine.run_ast_with_scope(&mut scope, &ast).unwrap());
}

// #[bench]
// fn bench_type_method_with_params(bench: &mut Bencher) {
// let script = "foo.update(1)";
#[bench]
fn bench_type_method_with_params(bench: &mut Bencher) {
let script = "foo.update(1)";

// let mut engine = Engine::new();
// engine.set_optimization_level(OptimizationLevel::None);
let mut engine = Engine::new();
engine.set_optimization_level(OptimizationLevel::None);

// engine.register_type_with_name::<Test>("Test");
// engine.register_fn("update", Test::update);
engine.register_type_with_name::<Test>("Test");
engine.register_fn("update", Test::update);

// let ast = engine.compile_expression(script).unwrap();
let ast = engine.compile_expression(script).unwrap();

// let mut scope = Scope::new();
// scope.push("foo", Test { x: 42 });
let mut scope = Scope::new();
scope.push("foo", Test { x: 42 });

// bench.iter(|| engine.run_ast_with_scope(&mut scope, &ast).unwrap());
// }
bench.iter(|| engine.run_ast_with_scope(&mut scope, &ast).unwrap());
}

#[bench]
fn bench_type_method_nested(bench: &mut Bencher) {
Expand Down
118 changes: 59 additions & 59 deletions benches/iterations.rs
Original file line number Diff line number Diff line change
@@ -1,78 +1,78 @@
#![feature(test)]
// #![feature(test)]

///! Test 1,000 iterations
extern crate test;
// ///! Test 1,000 iterations
// extern crate test;

use rhai::{Engine, OptimizationLevel, INT};
use test::Bencher;
// use rhai::{Engine, OptimizationLevel, INT};
// use test::Bencher;

#[bench]
fn bench_iterations_1000(bench: &mut Bencher) {
let script = "
let x = 1_000;
while x > 0 {
x -= 1;
}
";
// #[bench]
// fn bench_iterations_1000(bench: &mut Bencher) {
// let script = "
// let x = 1_000;

let mut engine = Engine::new();
engine.set_optimization_level(OptimizationLevel::None);
// while x > 0 {
// x -= 1;
// }
// ";

let ast = engine.compile(script).unwrap();
// let mut engine = Engine::new();
// engine.set_optimization_level(OptimizationLevel::None);

bench.iter(|| engine.run_ast(&ast).unwrap());
}
// let ast = engine.compile(script).unwrap();

#[bench]
fn bench_iterations_fibonacci(bench: &mut Bencher) {
let script = "
fn fibonacci(n) {
if n < 2 {
n
} else {
fibonacci(n-1) + fibonacci(n-2)
}
}
// bench.iter(|| engine.run_ast(&ast).unwrap());
// }

fibonacci(20)
";
// #[bench]
// fn bench_iterations_fibonacci(bench: &mut Bencher) {
// let script = "
// fn fibonacci(n) {
// if n < 2 {
// n
// } else {
// fibonacci(n-1) + fibonacci(n-2)
// }
// }

let mut engine = Engine::new();
engine.set_optimization_level(OptimizationLevel::None);
// fibonacci(20)
// ";

let ast = engine.compile(script).unwrap();
// let mut engine = Engine::new();
// engine.set_optimization_level(OptimizationLevel::None);

bench.iter(|| engine.eval_ast::<INT>(&ast).unwrap());
}
// let ast = engine.compile(script).unwrap();

#[bench]
fn bench_iterations_array(bench: &mut Bencher) {
let script = "
let x = [];
x.pad(1000, 0);
for i in 0..1000 { x[i] = i % 256; }
";
// bench.iter(|| engine.eval_ast::<INT>(&ast).unwrap());
// }

let mut engine = Engine::new();
engine.set_optimization_level(OptimizationLevel::None);
// #[bench]
// fn bench_iterations_array(bench: &mut Bencher) {
// let script = "
// let x = [];
// x.pad(1000, 0);
// for i in 0..1000 { x[i] = i % 256; }
// ";

let ast = engine.compile(script).unwrap();
// let mut engine = Engine::new();
// engine.set_optimization_level(OptimizationLevel::None);

bench.iter(|| engine.run_ast(&ast).unwrap());
}
// let ast = engine.compile(script).unwrap();

#[bench]
fn bench_iterations_blob(bench: &mut Bencher) {
let script = "
let x = blob(1000, 0);
for i in 0..1000 { x[i] = i % 256; }
";
// bench.iter(|| engine.run_ast(&ast).unwrap());
// }

let mut engine = Engine::new();
engine.set_optimization_level(OptimizationLevel::None);
// #[bench]
// fn bench_iterations_blob(bench: &mut Bencher) {
// let script = "
// let x = blob(1000, 0);
// for i in 0..1000 { x[i] = i % 256; }
// ";

let ast = engine.compile(script).unwrap();
// let mut engine = Engine::new();
// engine.set_optimization_level(OptimizationLevel::None);

bench.iter(|| engine.run_ast(&ast).unwrap());
}
// let ast = engine.compile(script).unwrap();

// bench.iter(|| engine.run_ast(&ast).unwrap());
// }

0 comments on commit 598966a

Please sign in to comment.