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]
|
#[bench]
|
||||||
fn bench_eval_array_loop(bench: &mut Bencher) {
|
fn bench_eval_array_loop(bench: &mut Bencher) {
|
||||||
let script = r#"
|
let script = "
|
||||||
let list = [];
|
let list = [];
|
||||||
|
|
||||||
for i in 0..10_000 {
|
for i in 0..10_000 {
|
||||||
@ -76,7 +76,7 @@ fn bench_eval_array_loop(bench: &mut Bencher) {
|
|||||||
for i in list {
|
for i in list {
|
||||||
sum += i;
|
sum += i;
|
||||||
}
|
}
|
||||||
"#;
|
";
|
||||||
|
|
||||||
let mut engine = Engine::new();
|
let mut engine = Engine::new();
|
||||||
engine.set_optimization_level(OptimizationLevel::None);
|
engine.set_optimization_level(OptimizationLevel::None);
|
||||||
|
@ -108,12 +108,12 @@ fn bench_eval_call(bench: &mut Bencher) {
|
|||||||
|
|
||||||
#[bench]
|
#[bench]
|
||||||
fn bench_eval_loop_number(bench: &mut Bencher) {
|
fn bench_eval_loop_number(bench: &mut Bencher) {
|
||||||
let script = r#"
|
let script = "
|
||||||
let s = 0;
|
let s = 0;
|
||||||
for x in 0..10000 {
|
for x in 0..10000 {
|
||||||
s += 1;
|
s += 1;
|
||||||
}
|
}
|
||||||
"#;
|
";
|
||||||
|
|
||||||
let mut engine = Engine::new();
|
let mut engine = Engine::new();
|
||||||
engine.set_optimization_level(OptimizationLevel::None);
|
engine.set_optimization_level(OptimizationLevel::None);
|
||||||
@ -159,7 +159,7 @@ fn bench_eval_loop_strings_no_build(bench: &mut Bencher) {
|
|||||||
|
|
||||||
#[bench]
|
#[bench]
|
||||||
fn bench_eval_switch(bench: &mut Bencher) {
|
fn bench_eval_switch(bench: &mut Bencher) {
|
||||||
let script = r#"
|
let script = "
|
||||||
let sum = 0;
|
let sum = 0;
|
||||||
let rem = 0;
|
let rem = 0;
|
||||||
|
|
||||||
@ -179,7 +179,7 @@ fn bench_eval_switch(bench: &mut Bencher) {
|
|||||||
9 => 1,
|
9 => 1,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"#;
|
";
|
||||||
|
|
||||||
let mut engine = Engine::new();
|
let mut engine = Engine::new();
|
||||||
engine.set_optimization_level(OptimizationLevel::None);
|
engine.set_optimization_level(OptimizationLevel::None);
|
||||||
@ -191,7 +191,7 @@ fn bench_eval_switch(bench: &mut Bencher) {
|
|||||||
|
|
||||||
#[bench]
|
#[bench]
|
||||||
fn bench_eval_nested_if(bench: &mut Bencher) {
|
fn bench_eval_nested_if(bench: &mut Bencher) {
|
||||||
let script = r#"
|
let script = "
|
||||||
let sum = 0;
|
let sum = 0;
|
||||||
let rem = 0;
|
let rem = 0;
|
||||||
|
|
||||||
@ -209,7 +209,7 @@ fn bench_eval_nested_if(bench: &mut Bencher) {
|
|||||||
else if rem == 8 { 42 }
|
else if rem == 8 { 42 }
|
||||||
else if rem == 9 { 1 };
|
else if rem == 9 { 1 };
|
||||||
}
|
}
|
||||||
"#;
|
";
|
||||||
|
|
||||||
let mut engine = Engine::new();
|
let mut engine = Engine::new();
|
||||||
engine.set_optimization_level(OptimizationLevel::None);
|
engine.set_optimization_level(OptimizationLevel::None);
|
||||||
|
@ -8,10 +8,10 @@ use test::Bencher;
|
|||||||
|
|
||||||
#[bench]
|
#[bench]
|
||||||
fn bench_eval_module(bench: &mut Bencher) {
|
fn bench_eval_module(bench: &mut Bencher) {
|
||||||
let script = r#"
|
let script = "
|
||||||
fn foo(x) { x + 1 }
|
fn foo(x) { x + 1 }
|
||||||
fn bar(x) { foo(x) }
|
fn bar(x) { foo(x) }
|
||||||
"#;
|
";
|
||||||
|
|
||||||
let mut engine = Engine::new();
|
let mut engine = Engine::new();
|
||||||
engine.set_optimization_level(OptimizationLevel::None);
|
engine.set_optimization_level(OptimizationLevel::None);
|
||||||
@ -24,10 +24,10 @@ fn bench_eval_module(bench: &mut Bencher) {
|
|||||||
|
|
||||||
let ast = engine
|
let ast = engine
|
||||||
.compile(
|
.compile(
|
||||||
r#"
|
"
|
||||||
fn foo(x) { x - 1 }
|
fn foo(x) { x - 1 }
|
||||||
testing::bar(41)
|
testing::bar(41)
|
||||||
"#,
|
",
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
@ -41,11 +41,11 @@ fn bench_eval_function_call(bench: &mut Bencher) {
|
|||||||
|
|
||||||
let ast = engine
|
let ast = engine
|
||||||
.compile(
|
.compile(
|
||||||
r#"
|
"
|
||||||
fn foo(x) { x - 1 }
|
fn foo(x) { x - 1 }
|
||||||
fn bar(x) { foo(x) }
|
fn bar(x) { foo(x) }
|
||||||
bar(41)
|
bar(41)
|
||||||
"#,
|
",
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -8,13 +8,13 @@ use test::Bencher;
|
|||||||
|
|
||||||
#[bench]
|
#[bench]
|
||||||
fn bench_iterations_1000(bench: &mut Bencher) {
|
fn bench_iterations_1000(bench: &mut Bencher) {
|
||||||
let script = r#"
|
let script = "
|
||||||
let x = 1_000;
|
let x = 1_000;
|
||||||
|
|
||||||
while x > 0 {
|
while x > 0 {
|
||||||
x -= 1;
|
x -= 1;
|
||||||
}
|
}
|
||||||
"#;
|
";
|
||||||
|
|
||||||
let mut engine = Engine::new();
|
let mut engine = Engine::new();
|
||||||
engine.set_optimization_level(OptimizationLevel::None);
|
engine.set_optimization_level(OptimizationLevel::None);
|
||||||
@ -26,7 +26,7 @@ fn bench_iterations_1000(bench: &mut Bencher) {
|
|||||||
|
|
||||||
#[bench]
|
#[bench]
|
||||||
fn bench_iterations_fibonacci(bench: &mut Bencher) {
|
fn bench_iterations_fibonacci(bench: &mut Bencher) {
|
||||||
let script = r#"
|
let script = "
|
||||||
fn fibonacci(n) {
|
fn fibonacci(n) {
|
||||||
if n < 2 {
|
if n < 2 {
|
||||||
n
|
n
|
||||||
@ -36,7 +36,7 @@ fn bench_iterations_fibonacci(bench: &mut Bencher) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fibonacci(20)
|
fibonacci(20)
|
||||||
"#;
|
";
|
||||||
|
|
||||||
let mut engine = Engine::new();
|
let mut engine = Engine::new();
|
||||||
engine.set_optimization_level(OptimizationLevel::None);
|
engine.set_optimization_level(OptimizationLevel::None);
|
||||||
@ -48,11 +48,11 @@ fn bench_iterations_fibonacci(bench: &mut Bencher) {
|
|||||||
|
|
||||||
#[bench]
|
#[bench]
|
||||||
fn bench_iterations_array(bench: &mut Bencher) {
|
fn bench_iterations_array(bench: &mut Bencher) {
|
||||||
let script = r#"
|
let script = "
|
||||||
let x = [];
|
let x = [];
|
||||||
x.pad(1000, 0);
|
x.pad(1000, 0);
|
||||||
for i in 0..1000 { x[i] = i % 256; }
|
for i in 0..1000 { x[i] = i % 256; }
|
||||||
"#;
|
";
|
||||||
|
|
||||||
let mut engine = Engine::new();
|
let mut engine = Engine::new();
|
||||||
engine.set_optimization_level(OptimizationLevel::None);
|
engine.set_optimization_level(OptimizationLevel::None);
|
||||||
@ -64,10 +64,10 @@ fn bench_iterations_array(bench: &mut Bencher) {
|
|||||||
|
|
||||||
#[bench]
|
#[bench]
|
||||||
fn bench_iterations_blob(bench: &mut Bencher) {
|
fn bench_iterations_blob(bench: &mut Bencher) {
|
||||||
let script = r#"
|
let script = "
|
||||||
let x = blob(1000, 0);
|
let x = blob(1000, 0);
|
||||||
for i in 0..1000 { x[i] = i % 256; }
|
for i in 0..1000 { x[i] = i % 256; }
|
||||||
"#;
|
";
|
||||||
|
|
||||||
let mut engine = Engine::new();
|
let mut engine = Engine::new();
|
||||||
engine.set_optimization_level(OptimizationLevel::None);
|
engine.set_optimization_level(OptimizationLevel::None);
|
||||||
|
@ -64,7 +64,7 @@ fn bench_parse_map(bench: &mut Bencher) {
|
|||||||
|
|
||||||
#[bench]
|
#[bench]
|
||||||
fn bench_parse_primes(bench: &mut Bencher) {
|
fn bench_parse_primes(bench: &mut Bencher) {
|
||||||
let script = r#"
|
let script = "
|
||||||
// This script uses the Sieve of Eratosthenes to calculate prime numbers.
|
// This script uses the Sieve of Eratosthenes to calculate prime numbers.
|
||||||
|
|
||||||
let now = timestamp();
|
let now = timestamp();
|
||||||
@ -79,7 +79,7 @@ fn bench_parse_primes(bench: &mut Bencher) {
|
|||||||
|
|
||||||
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] {
|
if prime_mask[p] {
|
||||||
print(p);
|
print(p);
|
||||||
|
|
||||||
@ -95,7 +95,7 @@ fn bench_parse_primes(bench: &mut Bencher) {
|
|||||||
|
|
||||||
print(`Total ${total_primes_found} primes.`);
|
print(`Total ${total_primes_found} primes.`);
|
||||||
print(`Run time = ${now.elapsed} seconds.`);
|
print(`Run time = ${now.elapsed} seconds.`);
|
||||||
"#;
|
";
|
||||||
|
|
||||||
let mut engine = Engine::new();
|
let mut engine = Engine::new();
|
||||||
engine.set_optimization_level(OptimizationLevel::None);
|
engine.set_optimization_level(OptimizationLevel::None);
|
||||||
|
@ -8,29 +8,29 @@ use test::Bencher;
|
|||||||
|
|
||||||
// This script uses the Sieve of Eratosthenes to calculate prime numbers.
|
// This script uses the Sieve of Eratosthenes to calculate prime numbers.
|
||||||
|
|
||||||
const SCRIPT: &str = r#"
|
const SCRIPT: &str = "
|
||||||
const MAX_NUMBER_TO_CHECK = 1_000; // 168 primes <= 1000
|
const MAX_NUMBER_TO_CHECK = 1_000; // 168 primes <= 1000
|
||||||
|
|
||||||
let prime_mask = [];
|
let prime_mask = [];
|
||||||
prime_mask.pad(MAX_NUMBER_TO_CHECK, true);
|
prime_mask.pad(MAX_NUMBER_TO_CHECK, true);
|
||||||
|
|
||||||
prime_mask[0] = false;
|
prime_mask[0] = false;
|
||||||
prime_mask[1] = 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] {
|
if prime_mask[p] {
|
||||||
total_primes_found += 1;
|
total_primes_found += 1;
|
||||||
let i = 2 * p;
|
let i = 2 * p;
|
||||||
|
|
||||||
while i < MAX_NUMBER_TO_CHECK {
|
while i < MAX_NUMBER_TO_CHECK {
|
||||||
prime_mask[i] = false;
|
prime_mask[i] = false;
|
||||||
i += p;
|
i += p;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
";
|
||||||
"#;
|
|
||||||
|
|
||||||
#[bench]
|
#[bench]
|
||||||
fn bench_eval_primes(bench: &mut Bencher) {
|
fn bench_eval_primes(bench: &mut Bencher) {
|
||||||
|
Loading…
Reference in New Issue
Block a user