2019-02-22 20:07:07 +00:00
|
|
|
#[macro_use]
|
|
|
|
extern crate criterion;
|
|
|
|
use criterion::Criterion;
|
2019-02-22 21:02:28 +00:00
|
|
|
use tempfile::tempdir;
|
2019-02-22 20:07:07 +00:00
|
|
|
use wasmer_runtime::{
|
|
|
|
cache::{Cache, FileSystemCache, WasmHash},
|
2019-02-22 20:20:16 +00:00
|
|
|
compile, validate,
|
2019-02-22 20:07:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static NGINX_WASM: &'static [u8] = include_bytes!("../../../examples/nginx/nginx.wasm");
|
|
|
|
|
|
|
|
fn compile_module() {
|
|
|
|
compile(NGINX_WASM).unwrap();
|
|
|
|
}
|
|
|
|
|
2019-02-22 21:02:28 +00:00
|
|
|
fn load_module(hash: WasmHash, cache: &impl Cache) {
|
2019-02-22 22:07:03 +00:00
|
|
|
cache.load(hash).expect("could not load module");
|
2019-02-22 21:02:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn hashing_benchmark(c: &mut Criterion) {
|
|
|
|
c.bench_function("nginx HASH", |b| b.iter(|| WasmHash::generate(NGINX_WASM)));
|
2019-02-22 20:07:07 +00:00
|
|
|
}
|
|
|
|
|
2019-02-22 20:20:16 +00:00
|
|
|
fn validate_benchmark(c: &mut Criterion) {
|
|
|
|
c.bench_function("nginx validate", |b| b.iter(|| validate(NGINX_WASM)));
|
|
|
|
}
|
|
|
|
|
2019-02-22 20:07:07 +00:00
|
|
|
fn compile_benchmark(c: &mut Criterion) {
|
|
|
|
c.bench_function("nginx compile", |b| b.iter(|| compile_module()));
|
|
|
|
}
|
|
|
|
|
|
|
|
fn load_benchmark(c: &mut Criterion) {
|
|
|
|
c.bench_function("nginx load", |b| {
|
2019-02-22 22:07:03 +00:00
|
|
|
let tempdir = tempdir().unwrap();
|
|
|
|
let mut cache = unsafe {
|
|
|
|
FileSystemCache::new(tempdir.path()).expect("unable to create file system cache")
|
|
|
|
};
|
2019-02-22 20:07:07 +00:00
|
|
|
let module = compile(NGINX_WASM).unwrap();
|
2019-02-22 21:02:28 +00:00
|
|
|
let wasm_hash = WasmHash::generate(NGINX_WASM);
|
2019-02-22 22:07:03 +00:00
|
|
|
cache
|
|
|
|
.store(wasm_hash, module)
|
|
|
|
.expect("unable to store into cache");
|
2019-02-22 20:07:07 +00:00
|
|
|
|
2019-02-22 21:02:28 +00:00
|
|
|
b.iter(|| load_module(wasm_hash, &cache))
|
2019-02-22 20:07:07 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
criterion_group! {
|
|
|
|
name = benches;
|
|
|
|
config = Criterion::default().sample_size(10);
|
2019-02-22 21:02:28 +00:00
|
|
|
targets = validate_benchmark, hashing_benchmark, compile_benchmark, load_benchmark
|
2019-02-22 20:07:07 +00:00
|
|
|
}
|
|
|
|
criterion_main!(benches);
|