/WebAssembly_CHAM

Performance comparison between Web Assembly and JS using CHAM

Primary LanguageJavaScript

WebAssembly_CHAM


To build example file


$mkdir example // make folder
$cd example // enter example folder
$nano example.c //make c example file

#include <stdio.h>
int main(int argc, char ** argv) {
printf("github by kyu\n"); //waring Have to put '\n'. if not, can make error
return 0;
}

$emcc example.c -s WASM=1 -o example.html


How to run Web Assembly


$cd emsdk
$./emsdk activate --build=Release sdk-incoming-64bit binaryen-master-64bit
$source ./emsdk_env.sh --build=Release
$emcc example.c -s WASM=1 -o example.html

   ->If want to include some files(ex, txt or img etc.), you need to use other command line
   emcc can not access to files on disks. You just have block of memory. WASM code could be called from JS and also WASM could call JS function.
   So, if want to include some files use under command line without above.

$emcc example.c -s WASM=1 -o example.html --preload-file /Users/kyu/Desktop/WebAssembly/emsdk/WebTest/
   '/Users/kyu/Desktop/WebAssembly/emsdk/WebTest/' is the directory path that you want to include.

$emrun --no_browser example.html --port 8080 //the browser will run 6931 port. 8080 extends to 6931.

Once the HTTP server is running, you can access http://localhost:6931/example.html this link.
If you see 'github by kyu' on console, you are success complie Web Assembly!


To read txt file on Chrome

$npm install http-server -g
$http-server /Users/kyu/Desktop/WebAssembly/emsdk/WebTest -o

Once the HTTP server is running, you can access http://localhost:8080/example.html this link.


Elapsed Time Summary Using JS and WASM