diff options
| author | Henry Gressmann <mail@henrygressmann.de> | 2024-01-29 23:12:20 +0100 |
|---|---|---|
| committer | Henry Gressmann <mail@henrygressmann.de> | 2024-01-29 23:12:20 +0100 |
| commit | 4919d8c2f86f69f669a1afba2a28d5c344fe7197 (patch) | |
| tree | 02f4b0747ee217ddf59fdc459a2083a95961a557 /benches/util/mod.rs | |
| parent | 963ddd26a89490458e31d9d553dffafe5e350e96 (diff) | |
perf: improve benchmarks
Signed-off-by: Henry Gressmann <mail@henrygressmann.de>
Diffstat (limited to 'benches/util/mod.rs')
| -rw-r--r-- | benches/util/mod.rs | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/benches/util/mod.rs b/benches/util/mod.rs index 7baddb7..69510a5 100644 --- a/benches/util/mod.rs +++ b/benches/util/mod.rs @@ -1,6 +1,32 @@ +#![allow(dead_code)] + use tinywasm::{self, parser::Parser, types::TinyWasmModule}; -pub fn tinywasm_module(wasm: &[u8]) -> TinyWasmModule { +pub fn wasm_to_twasm(wasm: &[u8]) -> Vec<u8> { let parser = Parser::new(); - parser.parse_module_bytes(wasm).expect("parse_module_bytes") + let res = parser.parse_module_bytes(wasm).expect("parse_module_bytes"); + res.serialize_twasm().to_vec() +} + +#[inline] +pub fn twasm_to_module(twasm: &[u8]) -> tinywasm::Module { + unsafe { TinyWasmModule::from_twasm_unchecked(&twasm) }.into() +} + +pub fn tinywasm(twasm: &[u8]) -> (tinywasm::Store, tinywasm::ModuleInstance) { + use tinywasm::*; + let module = twasm_to_module(twasm); + let mut store = Store::default(); + let imports = Imports::default(); + let instance = ModuleInstance::instantiate(&mut store, module, Some(imports)).expect("instantiate"); + (store, instance) +} + +pub fn wasmi(wasm: &[u8]) -> (wasmi::Module, wasmi::Store<()>, wasmi::Linker<()>) { + use wasmi::*; + let engine = Engine::default(); + let module = wasmi::Module::new(&engine, wasm).expect("wasmi::Module::new"); + let store = Store::new(&engine, ()); + let linker = <Linker<()>>::new(&engine); + (module, store, linker) } |
