Fix benchmarks
This commit is contained in:
parent
80ccd52319
commit
97900320e1
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -8,29 +8,29 @@ 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 {
|
||||
if prime_mask[p] {
|
||||
total_primes_found += 1;
|
||||
let i = 2 * p;
|
||||
for p in 2..MAX_NUMBER_TO_CHECK {
|
||||
if prime_mask[p] {
|
||||
total_primes_found += 1;
|
||||
let i = 2 * p;
|
||||
|
||||
while i < MAX_NUMBER_TO_CHECK {
|
||||
prime_mask[i] = false;
|
||||
i += p;
|
||||
while i < MAX_NUMBER_TO_CHECK {
|
||||
prime_mask[i] = false;
|
||||
i += p;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
"#;
|
||||
";
|
||||
|
||||
#[bench]
|
||||
fn bench_eval_primes(bench: &mut Bencher) {
|
||||
|
Loading…
Reference in New Issue
Block a user