From 2e9807b17283f4dc1cac612461b22ac510ca9a54 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Tue, 23 Nov 2021 18:09:41 +0800 Subject: [PATCH] Add benchmark. --- benches/iterations.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/benches/iterations.rs b/benches/iterations.rs index 243756ae..e414a69e 100644 --- a/benches/iterations.rs +++ b/benches/iterations.rs @@ -45,3 +45,34 @@ fn bench_iterations_fibonacci(bench: &mut Bencher) { bench.iter(|| engine.eval_ast::(&ast).unwrap()); } + +#[bench] +fn bench_iterations_array(bench: &mut Bencher) { + let script = r#" + let x = []; + x.pad(1000, 0); + for i in range(0, 1000) { x[i] = i % 256; } + "#; + + let mut engine = Engine::new(); + engine.set_optimization_level(OptimizationLevel::None); + + let ast = engine.compile(script).unwrap(); + + bench.iter(|| engine.run_ast(&ast).unwrap()); +} + +#[bench] +fn bench_iterations_blob(bench: &mut Bencher) { + let script = r#" + let x = blob(1000, 0); + for i in range(0, 1000) { x[i] = i % 256; } + "#; + + let mut engine = Engine::new(); + engine.set_optimization_level(OptimizationLevel::None); + + let ast = engine.compile(script).unwrap(); + + bench.iter(|| engine.run_ast(&ast).unwrap()); +}