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

Function func_wrap_host_buf_api

benches/compile_time_builtins.rs:303–335  ·  view source on GitHub ↗
(b: &mut Bencher<'_>)

Source from the content-addressed store, hash-verified

301 "#;
302
303 fn func_wrap_host_buf_api(b: &mut Bencher<'_>) -> Result<()> {
304 let engine = make_engine()?;
305 let linker = make_linker(&engine)?;
306 let component = Component::new(&engine, HOST_BUF_API_GUEST_WASM.as_bytes())?;
307
308 let iter_func = |iters| -> Result<_> {
309 let mut store = Store::new(
310 &engine,
311 ExposedBuf::new(std::iter::repeat_n(0u8, HOST_BUF_LEN)),
312 );
313 let instance = linker.instantiate(&mut store, &component)?;
314 let main = instance.get_typed_func::<(), ()>(&mut store, "main")?;
315
316 let start = Instant::now();
317 for _ in 0..iters {
318 main.call(&mut store, ())?;
319 }
320 let elapsed = start.elapsed();
321
322 let expected = iters as u8;
323 store.data().get().iter().enumerate().for_each(|(i, byte)| {
324 assert_eq!(
325 *byte, expected,
326 "buf[{i}] = {byte}, but should be {expected}"
327 )
328 });
329
330 Ok(elapsed)
331 };
332 b.iter_custom(|iters| iter_func(iters).unwrap());
333
334 Ok(())
335 }
336
337 fn compile_time_builtins_host_buf_api(b: &mut Bencher<'_>) -> Result<()> {
338 let engine = make_engine()?;

Callers 1

benchFunction · 0.85

Calls 12

make_linkerFunction · 0.85
OkFunction · 0.85
get_random_indexFunction · 0.85
as_bytesMethod · 0.80
make_engineFunction · 0.70
newFunction · 0.50
instantiateMethod · 0.45
callMethod · 0.45
iterMethod · 0.45
getMethod · 0.45
dataMethod · 0.45
unwrapMethod · 0.45

Tested by

no test coverage detected