-
Notifications
You must be signed in to change notification settings - Fork 840
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into feature/more-wasi-syscalls
- Loading branch information
Showing
17 changed files
with
192 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
extern "C" { | ||
fn it_works() -> i32; | ||
} | ||
|
||
#[no_mangle] | ||
pub fn plugin_entrypoint(n: i32) -> i32 { | ||
let result = unsafe { it_works() }; | ||
result + n | ||
} | ||
|
||
fn main() {} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
#[macro_use] | ||
extern crate criterion; | ||
use criterion::Criterion; | ||
use tempfile::tempdir; | ||
use wasmer_runtime::{ | ||
cache::{Cache, FileSystemCache, WasmHash}, | ||
compile, func, imports, instantiate, validate, ImportObject, | ||
}; | ||
use wasmer_runtime_core::vm::Ctx; | ||
|
||
fn it_works(_ctx: &mut Ctx) -> i32 { | ||
5 | ||
} | ||
|
||
static SIMPLE_WASM: &[u8] = include_bytes!(concat!( | ||
env!("CARGO_MANIFEST_DIR"), | ||
"/../../examples/no_abi_simple_plugin.wasm" | ||
)); | ||
|
||
fn hashing_benchmark(c: &mut Criterion) { | ||
c.bench_function("HASH", |b| b.iter(|| WasmHash::generate(SIMPLE_WASM))); | ||
} | ||
|
||
fn validate_benchmark(c: &mut Criterion) { | ||
c.bench_function("validate", |b| b.iter(|| validate(SIMPLE_WASM))); | ||
} | ||
|
||
fn compile_benchmark(c: &mut Criterion) { | ||
c.bench_function("compile", |b| b.iter(|| compile(SIMPLE_WASM))); | ||
} | ||
|
||
fn create_instance_benchmark(c: &mut Criterion) { | ||
let imports = imports!( | ||
"env" => { | ||
"it_works" => func!(it_works), | ||
}, | ||
); | ||
c.bench_function("instantiate", move |b| { | ||
b.iter(|| instantiate(&SIMPLE_WASM[..], &imports).unwrap()) | ||
}); | ||
} | ||
|
||
fn create_instance_from_cache_benchmark(c: &mut Criterion) { | ||
let imports = imports!( | ||
"env" => { | ||
"it_works" => func!(it_works), | ||
}, | ||
); | ||
let tempdir = tempdir().unwrap(); | ||
let mut cache = unsafe { | ||
FileSystemCache::new(tempdir.path()).expect("unable to create file system cache") | ||
}; | ||
let module = compile(SIMPLE_WASM).unwrap(); | ||
let hash = WasmHash::generate(SIMPLE_WASM); | ||
cache | ||
.store(hash, module) | ||
.expect("unable to store into cache"); | ||
c.bench_function("instantiate from cache", move |b| { | ||
b.iter(|| { | ||
let module = cache.load(hash).unwrap(); | ||
module.instantiate(&imports).unwrap(); | ||
}) | ||
}); | ||
} | ||
|
||
fn calling_fn_benchmark(c: &mut Criterion) { | ||
let imports = imports!( | ||
"env" => { | ||
"it_works" => func!(it_works), | ||
}, | ||
); | ||
let instance = instantiate(SIMPLE_WASM, &imports).unwrap(); | ||
c.bench_function("calling fn", move |b| { | ||
let entry_point = instance.func::<(i32), i32>("plugin_entrypoint").unwrap(); | ||
b.iter(|| entry_point.call(2).unwrap()) | ||
}); | ||
} | ||
|
||
criterion_group! { | ||
name = instance_bench; | ||
config = Criterion::default().sample_size(20); | ||
targets = compile_benchmark, validate_benchmark, hashing_benchmark, create_instance_from_cache_benchmark, calling_fn_benchmark, create_instance_benchmark, | ||
} | ||
criterion_main!(instance_bench); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,4 +15,4 @@ libc = "0.2.60" | |
[build-dependencies] | ||
cmake = "0.1.40" | ||
bindgen = "0.51.0" | ||
regex = "1.2.0" | ||
regex = "1.2.1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters