UNPKG

wasmonkey

Version:

Write and run C code inside JavaScript file.

40 lines (30 loc) 862 B
const Wasmonkey = require("./src/Wasmonkey"); const wasmonkey = new Wasmonkey(); wasmonkey.put(` #include "stdio.h" __macro int factorial(int n) { return n != 0 ? n*factorial(n-1) : 1; } `); function factorial(n) { return n !== 0 ? n*factorial(n-1) : 1; } wasmonkey.load(); console.log(wasmonkey.factorial(15)); // console.log() // console.time('clang'); wasmonkey.factorial(15); console.timeEnd('clang'); // run_fact(10e7, 15) // suite // .add('clang', ()=>wasmonkey.factorial(n)) // .add('js', ()=>factorial(n)) // // add listeners // .on('cycle', function(event) { // console.log(String(event.target)); // }) // .on('complete', function() { // console.log('Fastest is ' + this.filter('fastest').map('name')); // }) // // run async // .run({ 'async': true }); // wasmonkey.factorial(15);