Browse Source

switch eager vs lazy instantiation to a criterion bench

pull/2946/head
Pat Hickey 3 years ago
parent
commit
2a4c51b77d
  1. 4
      Cargo.toml
  2. 74
      benches/thread_eager_init.rs
  3. 1
      tests/all/main.rs

4
Cargo.toml

@ -120,3 +120,7 @@ debug = false # FIXME(#1813)
[[bench]]
name = "instantiation"
harness = false
[[bench]]
name = "thread_eager_init"
harness = false

74
tests/all/thread_eager_init.rs → benches/thread_eager_init.rs

@ -1,11 +1,47 @@
use anyhow::Result;
use criterion::{criterion_group, criterion_main, Criterion};
use std::thread;
use std::time::{Duration, Instant};
use wasmtime::*;
#[test]
fn measure_execution_time() -> Result<()> {
let iterations = 1000;
fn measure_execution_time(c: &mut Criterion) {
c.bench_function("lazy initialization at call", move |b| {
let (engine, module) = test_engine();
b.iter_custom(move |iters| {
(0..iters)
.into_iter()
.map(|_| lazy_thread_instantiate(engine.clone(), module.clone()))
.sum()
})
});
c.bench_function("eager initialization", move |b| {
let (engine, module) = test_engine();
b.iter_custom(move |iters| {
(0..iters)
.into_iter()
.map(|_| {
let (init, _call) = eager_thread_instantiate(engine.clone(), module.clone());
init
})
.sum()
})
});
c.bench_function("call after eager initialization", move |b| {
let (engine, module) = test_engine();
b.iter_custom(move |iters| {
(0..iters)
.into_iter()
.map(|_| {
let (_init, call) = eager_thread_instantiate(engine.clone(), module.clone());
call
})
.sum()
})
});
}
fn test_engine() -> (Engine, Module) {
let pool_count = 1000;
let mut config = Config::new();
config.allocation_strategy(InstanceAllocationStrategy::Pooling {
@ -15,33 +51,14 @@ fn measure_execution_time() -> Result<()> {
..Default::default()
},
instance_limits: InstanceLimits {
count: iterations * 2,
count: pool_count,
memory_reservation_size: 1,
},
});
let engine = Engine::new(&config)?;
let module = Module::new(&engine, r#"(module (memory 1) (func (export "f")))"#)?;
let lazy_call_time: Duration = (0..iterations)
.into_iter()
.map(|_| lazy_thread_instantiate(engine.clone(), module.clone()))
.sum();
let (eager_init_total, eager_call_total): (Duration, Duration) = (0..iterations)
.into_iter()
.map(|_| eager_thread_instantiate(engine.clone(), module.clone()))
.fold(
(Duration::default(), Duration::default()),
|(s1, s2), (d1, d2)| (s1 + d1, s2 + d2),
);
println!(
"lazy call: {:?}, eager init: {:?}, eager call: {:?}",
lazy_call_time, eager_init_total, eager_call_total
);
Ok(())
let engine = Engine::new(&config).unwrap();
let module = Module::new(&engine, r#"(module (memory 1) (func (export "f")))"#).unwrap();
(engine, module)
}
fn lazy_thread_instantiate(engine: Engine, module: Module) -> Duration {
@ -77,3 +94,6 @@ fn eager_thread_instantiate(engine: Engine, module: Module) -> (Duration, Durati
.join()
.expect("thread joins")
}
criterion_group!(benches, measure_execution_time);
criterion_main!(benches);

1
tests/all/main.rs

@ -24,7 +24,6 @@ mod pooling_allocator;
mod stack_overflow;
mod store;
mod table;
mod thread_eager_init;
mod traps;
mod wast;

Loading…
Cancel
Save