MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / measure_execution_time

Function measure_execution_time

benches/thread_eager_init.rs:6–47  ·  view source on GitHub ↗
(c: &mut Criterion)

Source from the content-addressed store, hash-verified

4use wasmtime::*;
5
6fn measure_execution_time(c: &mut Criterion) {
7 // Baseline performance: a single measurement covers both initializing
8 // thread local resources and executing the first call.
9 //
10 // The other two bench functions should sum to this duration.
11 c.bench_function("lazy initialization at call", move |b| {
12 let (engine, module) = test_setup();
13 b.iter_custom(move |iters| {
14 (0..iters)
15 .map(|_| lazy_thread_instantiate(engine.clone(), module.clone()))
16 .sum()
17 })
18 });
19
20 // Using Engine::tls_eager_initialize: measure how long eager
21 // initialization takes on a new thread.
22 c.bench_function("eager initialization", move |b| {
23 let (engine, module) = test_setup();
24 b.iter_custom(move |iters| {
25 (0..iters)
26 .map(|_| {
27 let (init, _call) = eager_thread_instantiate(engine.clone(), module.clone());
28 init
29 })
30 .sum()
31 })
32 });
33
34 // Measure how long the first call takes on a thread after it has been
35 // eagerly initialized.
36 c.bench_function("call after eager initialization", move |b| {
37 let (engine, module) = test_setup();
38 b.iter_custom(move |iters| {
39 (0..iters)
40 .map(|_| {
41 let (_init, call) = eager_thread_instantiate(engine.clone(), module.clone());
42 call
43 })
44 .sum()
45 })
46 });
47}
48
49/// Creating a store and measuring the time to perform a call is the same behavior
50/// in both setups.

Callers

nothing calls this directly

Calls 6

test_setupFunction · 0.85
lazy_thread_instantiateFunction · 0.85
eager_thread_instantiateFunction · 0.85
sumMethod · 0.80
mapMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected