Fix benchmarks

This commit is contained in:
Stephen Chung 2021-12-30 22:53:59 +08:00
parent 80ccd52319
commit 97900320e1
6 changed files with 41 additions and 41 deletions

View File

@ -64,7 +64,7 @@ fn bench_eval_array_large_set(bench: &mut Bencher) {
#[bench]
fn bench_eval_array_loop(bench: &mut Bencher) {
let script = r#"
let script = "
let list = [];
for i in 0..10_000 {
@ -76,7 +76,7 @@ fn bench_eval_array_loop(bench: &mut Bencher) {
for i in list {
sum += i;
}
"#;
";
let mut engine = Engine::new();
engine.set_optimization_level(OptimizationLevel::None);

View File

@ -108,12 +108,12 @@ fn bench_eval_call(bench: &mut Bencher) {
#[bench]
fn bench_eval_loop_number(bench: &mut Bencher) {
let script = r#"
let script = "
let s = 0;
for x in 0..10000 {
s += 1;
}
"#;
";
let mut engine = Engine::new();
engine.set_optimization_level(OptimizationLevel::None);
@ -159,7 +159,7 @@ fn bench_eval_loop_strings_no_build(bench: &mut Bencher) {
#[bench]
fn bench_eval_switch(bench: &mut Bencher) {
let script = r#"
let script = "
let sum = 0;
let rem = 0;
@ -179,7 +179,7 @@ fn bench_eval_switch(bench: &mut Bencher) {
9 => 1,
}
}
"#;
";
let mut engine = Engine::new();
engine.set_optimization_level(OptimizationLevel::None);
@ -191,7 +191,7 @@ fn bench_eval_switch(bench: &mut Bencher) {
#[bench]
fn bench_eval_nested_if(bench: &mut Bencher) {
let script = r#"
let script = "
let sum = 0;
let rem = 0;
@ -209,7 +209,7 @@ fn bench_eval_nested_if(bench: &mut Bencher) {
else if rem == 8 { 42 }
else if rem == 9 { 1 };
}
"#;
";
let mut engine = Engine::new();
engine.set_optimization_level(OptimizationLevel::None);

View File

@ -8,10 +8,10 @@ use test::Bencher;
#[bench]
fn bench_eval_module(bench: &mut Bencher) {
let script = r#"
let script = "
fn foo(x) { x + 1 }
fn bar(x) { foo(x) }
"#;
";
let mut engine = Engine::new();
engine.set_optimization_level(OptimizationLevel::None);
@ -24,10 +24,10 @@ fn bench_eval_module(bench: &mut Bencher) {
let ast = engine
.compile(
r#"
"
fn foo(x) { x - 1 }
testing::bar(41)
"#,
",
)
.unwrap();
@ -41,11 +41,11 @@ fn bench_eval_function_call(bench: &mut Bencher) {
let ast = engine
.compile(
r#"
"
fn foo(x) { x - 1 }
fn bar(x) { foo(x) }
bar(41)
"#,
",
)
.unwrap();

View File

@ -8,13 +8,13 @@ use test::Bencher;
#[bench]
fn bench_iterations_1000(bench: &mut Bencher) {
let script = r#"
let script = "
let x = 1_000;
while x > 0 {
x -= 1;
}
"#;
";
let mut engine = Engine::new();
engine.set_optimization_level(OptimizationLevel::None);
@ -26,7 +26,7 @@ fn bench_iterations_1000(bench: &mut Bencher) {
#[bench]
fn bench_iterations_fibonacci(bench: &mut Bencher) {
let script = r#"
let script = "
fn fibonacci(n) {
if n < 2 {
n
@ -36,7 +36,7 @@ fn bench_iterations_fibonacci(bench: &mut Bencher) {
}
fibonacci(20)
"#;
";
let mut engine = Engine::new();
engine.set_optimization_level(OptimizationLevel::None);
@ -48,11 +48,11 @@ fn bench_iterations_fibonacci(bench: &mut Bencher) {
#[bench]
fn bench_iterations_array(bench: &mut Bencher) {
let script = r#"
let script = "
let x = [];
x.pad(1000, 0);
for i in 0..1000 { x[i] = i % 256; }
"#;
";
let mut engine = Engine::new();
engine.set_optimization_level(OptimizationLevel::None);
@ -64,10 +64,10 @@ fn bench_iterations_array(bench: &mut Bencher) {
#[bench]
fn bench_iterations_blob(bench: &mut Bencher) {
let script = r#"
let script = "
let x = blob(1000, 0);
for i in 0..1000 { x[i] = i % 256; }
"#;
";
let mut engine = Engine::new();
engine.set_optimization_level(OptimizationLevel::None);

View File

@ -64,7 +64,7 @@ fn bench_parse_map(bench: &mut Bencher) {
#[bench]
fn bench_parse_primes(bench: &mut Bencher) {
let script = r#"
let script = "
// This script uses the Sieve of Eratosthenes to calculate prime numbers.
let now = timestamp();
@ -79,7 +79,7 @@ fn bench_parse_primes(bench: &mut Bencher) {
let total_primes_found = 0;
for p in 2..=MAX_NUMBER_TO_CHECK {
for p in 2..MAX_NUMBER_TO_CHECK {
if prime_mask[p] {
print(p);
@ -95,7 +95,7 @@ fn bench_parse_primes(bench: &mut Bencher) {
print(`Total ${total_primes_found} primes.`);
print(`Run time = ${now.elapsed} seconds.`);
"#;
";
let mut engine = Engine::new();
engine.set_optimization_level(OptimizationLevel::None);

View File

@ -8,18 +8,18 @@ use test::Bencher;
// This script uses the Sieve of Eratosthenes to calculate prime numbers.
const SCRIPT: &str = r#"
const MAX_NUMBER_TO_CHECK = 1_000; // 168 primes <= 1000
const SCRIPT: &str = "
const MAX_NUMBER_TO_CHECK = 1_000; // 168 primes <= 1000
let prime_mask = [];
prime_mask.pad(MAX_NUMBER_TO_CHECK, true);
let prime_mask = [];
prime_mask.pad(MAX_NUMBER_TO_CHECK, true);
prime_mask[0] = false;
prime_mask[1] = false;
prime_mask[0] = false;
prime_mask[1] = false;
let total_primes_found = 0;
let total_primes_found = 0;
for p in 2..=MAX_NUMBER_TO_CHECK {
for p in 2..MAX_NUMBER_TO_CHECK {
if prime_mask[p] {
total_primes_found += 1;
let i = 2 * p;
@ -29,8 +29,8 @@ for p in 2..=MAX_NUMBER_TO_CHECK {
i += p;
}
}
}
"#;
}
";
#[bench]
fn bench_eval_primes(bench: &mut Bencher) {