Sometimes it's the rate of doing something which is the target that needs to be improved through optimisation. ie increase the widgets per second of some application. I've just been looking at a code that estimated performance by counting the number of computations completed in a known constant length of time. The code was showing a performance regression, and I wanted to find out what changed. The analysis is kind of counter intuitive, so I thought I'd share an example with you.

Here's an example code that does a computation for a fixed length of time, in this case about 30 seconds:

#include #include #include double f1(int i){ double t=0; while (i-->0) {t+=t;} return t;}double f2(int i){ double t=0; while (i-->0) {t+=t;} return t;}void main(int argc,char**args){ struct timeval now; long startsecs; long count=0; int vcount; if (argc!=2){ printf("Needs a number to be passed in\n"); exit(0);} vcount=atoi(args[1]); gettimeofday(&now,0); startsecs=now.tv_sec; do { f1(100); f2(vcount); count++; gettimeofday(&now,0); } while (now.tv_sec