def test_benchmark_nbody_with_ppci(benchmark): instance = wasm.instantiate(wasm.read_wasm(TEST_BYTES), {}, 'native') nbody = instance.exports.main def bench(): return nbody(N) assert benchmark(bench)
def test_load_save(self): """ Load program.wasm from disk and save it again. """ program_filename = os.path.join( THIS_DIR, '..', '..', 'examples', 'wasm', 'program.wasm') with open(program_filename, 'rb') as f: wasm_module = read_wasm(f) with open(program_filename, 'rb') as f: content1 = f.read() # Save to file: f = io.BytesIO() wasm_module.to_file(f) content2 = f.getvalue() # Compare contents: self.assertEqual(content1, content2)
def test_load_save_via_text(self): """ Round trip test via text format. This is a good stress/sanity test on both WAT generation and parsing. """ program_filename = os.path.join( THIS_DIR, '..', '..', 'examples', 'wasm', 'program.wasm') with open(program_filename, 'rb') as f: content1 = f.read() with open(program_filename, 'rb') as f: wasm_module = read_wasm(f) # convert to text format: wat_text = wasm_module.to_string() # Parse text format: f = io.StringIO(wat_text) wasm_module2 = read_wat(f) content2 = wasm_module2.to_bytes() self.assertEqual(content1, content2)
from ppci.wasm import instantiate, read_wasm import mandel import x import time with open('mandel.wasm', 'rb') as f: module = read_wasm(f) inst = instantiate(module, {'x': {'putc': x.putc}}) print(inst) print('python -> wasm -> native code mandel:') t1 = time.time() inst.exports['mandel']() t2 = time.time() print('Python mandel:') t3 = time.time() mandel.mandel() t4 = time.time() dt_native = t2 - t1 dt_python = t4 - t3 print('native took:', dt_native, 'python took:', dt_python, 'speedup', dt_python / dt_native)
import io from ppci.wasm import read_wasm with open('fact.wasm', 'rb') as f: m = read_wasm(f) print(m) m.show()