diff --git a/runtime/tests/big_fibonacci/get_time.h b/runtime/tests/big_fibonacci/get_time.h new file mode 100644 index 0000000..db2ffaf --- /dev/null +++ b/runtime/tests/big_fibonacci/get_time.h @@ -0,0 +1,44 @@ +#ifndef GET_TIME_H +#define GET_TIME_H + +#include +#include +#include + +#ifndef WASM +#ifndef CPU_FREQ +#define CPU_FREQ 1000 +#endif +#endif + +static unsigned long long +get_time() +{ +#if 0 + unsigned long long int ret = 0; + unsigned int cycles_lo; + unsigned int cycles_hi; + __asm__ volatile ("rdtsc" : "=a" (cycles_lo), "=d" (cycles_hi)); + ret = (unsigned long long int)cycles_hi << 32 | cycles_lo; + + return ret; +#else + struct timeval Tp; + int stat; + stat = gettimeofday(&Tp, NULL); + if (stat != 0) printf("Error return from gettimeofday: %d", stat); + return (Tp.tv_sec * 1000000 + Tp.tv_usec); +#endif +} + +static inline void +print_time(unsigned long long s, unsigned long long e) +{ +#if 0 + printf("%llu cycs, %llu us\n", e - s, (e - s) / CPU_FREQ); +#else + fprintf(stdout, "%llu us\n", e - s); +#endif +} + +#endif /* GET_TIME_H */ diff --git a/runtime/tests/big_fibonacci/main.c b/runtime/tests/big_fibonacci/main.c new file mode 100644 index 0000000..a5d05d8 --- /dev/null +++ b/runtime/tests/big_fibonacci/main.c @@ -0,0 +1,24 @@ +#include +// #include "get_time.h" +unsigned long int +fib(unsigned long int n) +{ + if (n <= 1) return n; + return fib(n - 1) + fib(n - 2); +} + +int +main(int argc, char **argv) +{ + unsigned long n = 0, r,r2,r3; + scanf("%lu", &n); + // unsigned long long st = get_time(), en; + r = fib(29); + r2 = fib(29); + r3 = fib(29); + // en = get_time(); + printf("%lu\n", r3); + + // print_time(st, en); + return 0; +} diff --git a/runtime/tests/big_fibonacci/run_fib.sh b/runtime/tests/big_fibonacci/run_fib.sh new file mode 100755 index 0000000..438b4ec --- /dev/null +++ b/runtime/tests/big_fibonacci/run_fib.sh @@ -0,0 +1,32 @@ +#!/bin/sh + +ITERS=$3 + +# before running this benchmark, +# copy fibonacci to fibonacci_native.out + +testeach() { + tmp_cnt=${ITERS} + exe_relpath=$1 + + echo "${exe_relpath} ($2) for ${tmp_cnt}" + + while [ ${tmp_cnt} -gt 0 ]; do + bench=$(echo $2 | $exe_relpath 2> /dev/null) + tmp_cnt=$((tmp_cnt - 1)) + echo "$bench" + done + + echo "Done!" +} + +MAXNUM=$2 + +tmp1_cnt=${MAXNUM} + +while [ ${tmp1_cnt} -gt 28 ]; do + testeach ./fibonacci_$1.out ${tmp1_cnt} + tmp1_cnt=$((tmp1_cnt - 1)) +done + +echo "All done!"