#include "bench.h" #include /* * Bubblesort * * This is a simple implementation of the bubblesort algorithm as it * is often found in application programs. */ void bubblesort(unsigned char * data) { int finished=0; int counter,buf; while (finished == 0) { finished=1; for (counter=1; data[counter]; counter++) if (data[counter-1] > data[counter]) { finished=0; buf=data[counter-1]; data[counter-1]=data[counter]; data[counter]=buf; } } } void test_bubblesort() { unsigned char buf[400]; int c, c2; timer_start(CONTEXT_LOCAL); for (c=0; c<100; c++) { strcpy((char*)buf, "AAvoidrecursion_f1(intnr){intx;for(x=nr;x>1;x--)rr" "DD(11);recursion_f1(11);recursion_f1(11);getrusage" "BBecursion_f1(nr-1);}intrecursion_test(){structrus" "CCageu1,u2;getrusage(RUSAGE_SELF,&u1);recursion_f1" "DD(11);recursion_f1(11);recursion_f1(11);getrusage" "EE(RUSAGE_SELF,&u2);return(u2.ru_utime.tv_sec*1000" "DD(11);recursion_f1(11);recursion_f1(11);getrusage" "FF000+u2.r_utime.tv_usec)-(u1.ru_utime.tv_sec*100"); bubblesort(buf); result_push(CONTEXT_LOCAL, buf[c]); result_push(CONTEXT_LOCAL, buf[c+100]); result_push(CONTEXT_LOCAL, buf[c+200]); result_push(CONTEXT_LOCAL, buf[c+300]); } for (c=0; c<100; c++) { for (c2=0; c2<400; c2+=2) { buf[c2+0] = (1000-c2) % 197 + 20; buf[c2+1] = (1000+c2) % 197 + 20; } buf[399]=0; bubblesort(buf); result_push(CONTEXT_LOCAL, buf[c]); result_push(CONTEXT_LOCAL, buf[c+100]); result_push(CONTEXT_LOCAL, buf[c+200]); result_push(CONTEXT_LOCAL, buf[c+300]); } timer_stop(CONTEXT_LOCAL); }