Add fast operators to benchmarks.
This commit is contained in:
parent
b3f6fa9ce8
commit
1ae0a4c761
@ -21,6 +21,10 @@ Deprecated API
|
|||||||
New features
|
New features
|
||||||
------------
|
------------
|
||||||
|
|
||||||
|
### Fast operators
|
||||||
|
|
||||||
|
* A new option `Engine::fast_operators` is introduced that short-circuits all built-in operators of built-in types for higher speed. User overloads are ignored. For operator-heavy scripts, this may yield substantial speed-up's.
|
||||||
|
|
||||||
### Fallible type iterators
|
### Fallible type iterators
|
||||||
|
|
||||||
* For very special needs, the ability to register fallible type iterators is added.
|
* For very special needs, the ability to register fallible type iterators is added.
|
||||||
@ -30,10 +34,6 @@ New features
|
|||||||
* `if`-expressions are allowed in `Engine::eval_expression` and `Engine::compile_expression` provided that both statement blocks each contain at most a single expression.
|
* `if`-expressions are allowed in `Engine::eval_expression` and `Engine::compile_expression` provided that both statement blocks each contain at most a single expression.
|
||||||
* `switch`-expressions are allowed in `Engine::eval_expression` and `Engine::compile_expression` provided that match actions are expressions only.
|
* `switch`-expressions are allowed in `Engine::eval_expression` and `Engine::compile_expression` provided that match actions are expressions only.
|
||||||
|
|
||||||
### Fast operators
|
|
||||||
|
|
||||||
* A new option `Engine::fast_operators` is introduced that short-circuits all built-in operators of built-in types for higher speed. User overloads are ignored. For operator-heavy scripts, this may yield substantial speed-up's.
|
|
||||||
|
|
||||||
Enhancements
|
Enhancements
|
||||||
------------
|
------------
|
||||||
|
|
||||||
|
@ -53,6 +53,23 @@ fn bench_eval_scope_longer(bench: &mut Bencher) {
|
|||||||
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_eval_scope_longer_fast_ops(bench: &mut Bencher) {
|
||||||
|
let script = "(requests_made * requests_succeeded / 100) >= 90";
|
||||||
|
|
||||||
|
let mut engine = Engine::new();
|
||||||
|
engine.set_optimization_level(OptimizationLevel::None);
|
||||||
|
engine.set_fast_operators(true);
|
||||||
|
|
||||||
|
let mut scope = Scope::new();
|
||||||
|
scope.push("requests_made", 99 as INT);
|
||||||
|
scope.push("requests_succeeded", 90 as INT);
|
||||||
|
|
||||||
|
let ast = engine.compile_expression(script).unwrap();
|
||||||
|
|
||||||
|
bench.iter(|| engine.run_ast_with_scope(&mut scope, &ast).unwrap());
|
||||||
|
}
|
||||||
|
|
||||||
#[bench]
|
#[bench]
|
||||||
fn bench_eval_scope_complex(bench: &mut Bencher) {
|
fn bench_eval_scope_complex(bench: &mut Bencher) {
|
||||||
let script = r#"
|
let script = r#"
|
||||||
|
6480
scripts/all_in_one.d.rhai
Normal file
6480
scripts/all_in_one.d.rhai
Normal file
File diff suppressed because it is too large
Load Diff
@ -2,7 +2,8 @@
|
|||||||
|
|
||||||
let now = timestamp();
|
let now = timestamp();
|
||||||
|
|
||||||
const MAX_NUMBER_TO_CHECK = 1_000_000; // 9592 primes <= 100000
|
const ANSWER = 78_498;
|
||||||
|
const MAX_NUMBER_TO_CHECK = 1_000_000;
|
||||||
|
|
||||||
let prime_mask = [];
|
let prime_mask = [];
|
||||||
prime_mask.pad(MAX_NUMBER_TO_CHECK + 1, true);
|
prime_mask.pad(MAX_NUMBER_TO_CHECK + 1, true);
|
||||||
@ -27,6 +28,6 @@ for p in 2..=MAX_NUMBER_TO_CHECK {
|
|||||||
print(`Total ${total_primes_found} primes <= ${MAX_NUMBER_TO_CHECK}`);
|
print(`Total ${total_primes_found} primes <= ${MAX_NUMBER_TO_CHECK}`);
|
||||||
print(`Run time = ${now.elapsed} seconds.`);
|
print(`Run time = ${now.elapsed} seconds.`);
|
||||||
|
|
||||||
if total_primes_found != 78_498 {
|
if total_primes_found != ANSWER {
|
||||||
print("The answer is WRONG! Should be 78,498!");
|
print(`The answer is WRONG! Should be ${ANSWER}!`);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user