1 extern crate parity_wasm;
2 extern crate time;
3 
4 use std::fs;
5 
rate(file_name: &'static str, iterations: u64)6 fn rate(file_name: &'static str, iterations: u64) {
7 	let file_size = fs::metadata(file_name).expect(&format!("{} to exist", file_name)).len();
8 	let mut total_ms = 0;
9 
10 	for _ in 0..iterations {
11 		let start = time::PreciseTime::now();
12 		let _module = parity_wasm::deserialize_file(file_name);
13 		let end = time::PreciseTime::now();
14 
15 		total_ms += start.to(end).num_milliseconds();
16 	}
17 
18 	println!("Rate for {}: {} MB/s", file_name,
19 		(file_size as f64 * iterations as f64 / (1024*1024) as f64) /  // total work megabytes
20 		(total_ms as f64 / 1000f64)									   // total seconds
21 	);
22 }
23 
main()24 fn main() {
25 	rate("./res/cases/v1/clang.wasm", 10);
26 	rate("./res/cases/v1/hello.wasm", 100);
27 	rate("./res/cases/v1/with_names.wasm", 100);
28 }