-
Notifications
You must be signed in to change notification settings - Fork 788
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #201 from wasmerio/feature/benchmarks
Add benchmark runner and nginx compile vs. load bench
- Loading branch information
Showing
8 changed files
with
312 additions
and
66 deletions.
There are no files selected for viewing
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
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,53 @@ | ||
#[macro_use] | ||
extern crate criterion; | ||
use criterion::Criterion; | ||
use tempfile::tempdir; | ||
use wasmer_runtime::{ | ||
cache::{Cache, FileSystemCache, WasmHash}, | ||
compile, validate, | ||
}; | ||
|
||
static NGINX_WASM: &'static [u8] = include_bytes!("../../../examples/nginx/nginx.wasm"); | ||
|
||
fn compile_module() { | ||
compile(NGINX_WASM).unwrap(); | ||
} | ||
|
||
fn load_module(hash: WasmHash, cache: &impl Cache) { | ||
cache.load(hash).expect("could not load module"); | ||
} | ||
|
||
fn hashing_benchmark(c: &mut Criterion) { | ||
c.bench_function("nginx HASH", |b| b.iter(|| WasmHash::generate(NGINX_WASM))); | ||
} | ||
|
||
fn validate_benchmark(c: &mut Criterion) { | ||
c.bench_function("nginx validate", |b| b.iter(|| validate(NGINX_WASM))); | ||
} | ||
|
||
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| { | ||
let tempdir = tempdir().unwrap(); | ||
let mut cache = unsafe { | ||
FileSystemCache::new(tempdir.path()).expect("unable to create file system cache") | ||
}; | ||
let module = compile(NGINX_WASM).unwrap(); | ||
let wasm_hash = WasmHash::generate(NGINX_WASM); | ||
cache | ||
.store(wasm_hash, module) | ||
.expect("unable to store into cache"); | ||
|
||
b.iter(|| load_module(wasm_hash, &cache)) | ||
}); | ||
} | ||
|
||
criterion_group! { | ||
name = benches; | ||
config = Criterion::default().sample_size(10); | ||
targets = validate_benchmark, hashing_benchmark, compile_benchmark, load_benchmark | ||
} | ||
criterion_main!(benches); |