forked from Mirrors/wasm3
parent
99f6011137
commit
805eb44a5c
@ -1,15 +1,22 @@
|
||||
## Compile
|
||||
|
||||
```sh
|
||||
wasicc -Oz wasi_printf.c -o wasi_printf.wasm
|
||||
|
||||
# Disassemble:
|
||||
wasm2wat wasi_printf.wasm -o wasi_printf.wat
|
||||
wasicc -O3 wasi_printf.c -o wasi_printf.wasm
|
||||
```
|
||||
|
||||
## Run
|
||||
|
||||
```sh
|
||||
../../build/wasm3 wasi_printf.wasm _start
|
||||
|
||||
$ENGINES_PATH/wasm-micro-runtime/core/iwasm/products/linux/build/iwasm wasi_printf.wasm
|
||||
|
||||
$ENGINES_PATH/wac/wax wasi_printf.wasm
|
||||
|
||||
$ENGINES_PATH/WAVM/Release/bin/wavm run wasi_printf.wasm
|
||||
|
||||
wasmer run wasi_printf.wasm
|
||||
|
||||
wasmer-js run wasi_printf.wasm
|
||||
```
|
||||
|
||||
|
@ -1,8 +1,48 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <time.h>
|
||||
|
||||
#define WASM_EXPORT __attribute__((used)) __attribute__((visibility ("default")))
|
||||
|
||||
struct timespec timespec_diff(struct timespec start, struct timespec end)
|
||||
{
|
||||
struct timespec temp;
|
||||
if ((end.tv_nsec-start.tv_nsec)<0) {
|
||||
temp.tv_sec = end.tv_sec-start.tv_sec-1;
|
||||
temp.tv_nsec = 1000000000+end.tv_nsec-start.tv_nsec;
|
||||
} else {
|
||||
temp.tv_sec = end.tv_sec-start.tv_sec;
|
||||
temp.tv_nsec = end.tv_nsec-start.tv_nsec;
|
||||
}
|
||||
return temp;
|
||||
}
|
||||
|
||||
WASM_EXPORT
|
||||
uint32_t fib(uint32_t n)
|
||||
{
|
||||
if(n < 2) {
|
||||
return n;
|
||||
}
|
||||
return fib(n-1) + fib(n-2);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
struct timespec start, finish;
|
||||
|
||||
// Chew up some CPU time
|
||||
volatile int n=38, result;
|
||||
|
||||
printf("Calculating fib(%d)...\n", n);
|
||||
|
||||
clock_gettime(CLOCK_REALTIME, &start);
|
||||
result = fib(n);
|
||||
clock_gettime(CLOCK_REALTIME, &finish);
|
||||
|
||||
struct timespec delta = timespec_diff(start, finish);
|
||||
|
||||
printf("Finished in: %lu ms\n", (delta.tv_sec*1000) + (delta.tv_nsec/1000000));
|
||||
//printf("ms: %lf\n", delta_s*1000.0 + delta_ns/1000000.0);
|
||||
|
||||
int main(int args, char* argv[]) {
|
||||
//puts("Hello world!");
|
||||
printf("Hell%x w%d%s!\n", 0, 0, "rld");
|
||||
return 0;
|
||||
}
|
||||
|
Binary file not shown.
Loading…
Reference in new issue