2020-04-19 12:33:09 +02:00
|
|
|
#![feature(test)]
|
|
|
|
|
|
|
|
///! Test evaluating expressions
|
|
|
|
extern crate test;
|
|
|
|
|
2021-03-15 04:36:30 +01:00
|
|
|
use rhai::{Array, Engine, Map, INT};
|
2020-04-19 12:33:09 +02:00
|
|
|
use test::Bencher;
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn bench_engine_new(bench: &mut Bencher) {
|
|
|
|
bench.iter(|| Engine::new());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn bench_engine_new_raw(bench: &mut Bencher) {
|
|
|
|
bench.iter(|| Engine::new_raw());
|
|
|
|
}
|
|
|
|
|
2020-04-20 18:11:25 +02:00
|
|
|
#[bench]
|
|
|
|
fn bench_engine_new_raw_core(bench: &mut Bencher) {
|
2020-04-22 13:10:13 +02:00
|
|
|
use rhai::packages::*;
|
2020-04-20 18:11:25 +02:00
|
|
|
let package = CorePackage::new();
|
|
|
|
|
|
|
|
bench.iter(|| {
|
|
|
|
let mut engine = Engine::new_raw();
|
2022-08-18 11:22:56 +02:00
|
|
|
package.register_into_engine(&mut engine);
|
2020-04-20 18:11:25 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-04-19 12:33:09 +02:00
|
|
|
#[bench]
|
|
|
|
fn bench_engine_register_fn(bench: &mut Bencher) {
|
2020-05-23 12:59:28 +02:00
|
|
|
fn hello(_a: INT, _b: Array, _c: Map) -> bool {
|
2020-04-19 12:33:09 +02:00
|
|
|
true
|
|
|
|
}
|
|
|
|
|
|
|
|
bench.iter(|| {
|
2020-04-24 10:20:03 +02:00
|
|
|
let mut engine = Engine::new_raw();
|
2020-04-19 12:33:09 +02:00
|
|
|
engine.register_fn("hello", hello);
|
|
|
|
});
|
|
|
|
}
|