Generate a .wasm file for every test, for size benchmarking

This commit is contained in:
Brian Carroll 2021-10-09 18:47:37 +01:00
parent d166f65a31
commit 32b9f4fb07

View file

@ -1,3 +1,5 @@
use std::cell::Cell;
use roc_can::builtins::builtin_defs_map; use roc_can::builtins::builtin_defs_map;
use roc_collections::all::{MutMap, MutSet}; use roc_collections::all::{MutMap, MutSet};
// use roc_std::{RocDec, RocList, RocOrder, RocStr}; // use roc_std::{RocDec, RocList, RocOrder, RocStr};
@ -6,6 +8,10 @@ use roc_gen_wasm::from_wasm32_memory::FromWasm32Memory;
const TEST_WRAPPER_NAME: &str = "test_wrapper"; const TEST_WRAPPER_NAME: &str = "test_wrapper";
std::thread_local! {
static TEST_COUNTER: Cell<u32> = Cell::new(0);
}
fn promote_expr_to_module(src: &str) -> String { fn promote_expr_to_module(src: &str) -> String {
let mut buffer = String::from("app \"test\" provides [ main ] to \"./platform\"\n\nmain =\n"); let mut buffer = String::from("app \"test\" provides [ main ] to \"./platform\"\n\nmain =\n");
@ -101,16 +107,27 @@ pub fn helper_wasm<'a, T: Wasm32TestResult>(
let module_bytes = builder.build().to_bytes().unwrap(); let module_bytes = builder.build().to_bytes().unwrap();
// for debugging (e.g. with wasm2wat) // for debugging (e.g. with wasm2wat)
if false { if true {
use std::io::Write; use std::io::Write;
let path = "/home/brian/Documents/roc/compiler/gen_wasm/debug.wasm";
match std::fs::File::create(path) { TEST_COUNTER.with(|test_count| -> () {
Err(e) => eprintln!("Problem creating wasm debug file: {:?}", e), let thread_id = std::thread::current().id();
Ok(mut file) => { let thread_num_string: String = format!("{:?}", thread_id).chars().filter(|c| c.is_digit(10)).collect();
file.write_all(&module_bytes).unwrap(); let thread_num: i64 = thread_num_string.parse().unwrap();
let path = format!(
"/home/brian/Documents/roc/compiler/gen_wasm/output/test-{:?}-{:?}.wasm",
thread_num,
test_count.get()
);
test_count.set(test_count.get() + 1);
match std::fs::File::create(path) {
Err(e) => eprintln!("Problem creating wasm debug file: {:?}", e),
Ok(mut file) => {
file.write_all(&module_bytes).unwrap();
}
} }
} });
} }
// now, do wasmer stuff // now, do wasmer stuff