upload big_fibonacci

main
xiaosuGW 3 years ago
parent 7e6cfdbeec
commit 17141a07aa

@ -0,0 +1,44 @@
#ifndef GET_TIME_H
#define GET_TIME_H
#include <time.h>
#include <sys/time.h>
#include <stdio.h>
#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 */

@ -0,0 +1,24 @@
#include <stdio.h>
// #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;
}

@ -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!"
Loading…
Cancel
Save