#include "bench.h" /* * Fibonacci Numbers * * Calculate the sum of all fibonacci numbers up to the Nth fibonacci * number. I'd guess this function could be highly optimized by using * registers and re-ordering assembler calls to let cpus which can do * it execute some statements in parallel. */ int get_sum_of_fibonacci(int n) { int last1 = 1, last2 = 0; int new, sum; for (sum=1; n>2; n--) { new = last1 + last2; sum += new; last2 = last1; last1 = new; } return sum; } void test_fibonacci() { int c; timer_start(CONTEXT_LOCAL); /* 251 is a prim number. ;-) */ for (c=100000; c<100800; c++) result_push(CONTEXT_LOCAL, get_sum_of_fibonacci(c) % 251); timer_stop(CONTEXT_LOCAL); }