I wouldn't want anything too short. Micro-benchmarks generally suck
at showing anything relevant for actual use.
You could check out the computer language shootout (although I think
it's a little misleading to allow a Java implementation that is one
just JNI call to native code).
Well, this "Micro-benchmark" falls clearly in the "too short" class,
but...
The results:
C: 126.5 MHz i386/32
C: 126.5 MHz x86/64
FF3.6: 29.3 MHz FireBug OFF
Chrome5.0.307.9: 26.8 MHz
v8-shell: 25.4 MHz version 2.1.1.1
FF3.5.8 21.2 MHz FireBug OFF
jsc: 9.0 MHz javascriptCore shell
Safari4.0.4: 7.9 MHz javascriptCore
Safari4.0.4: 1.8 MHz webInspector console
FF 3.0.15: 1.7 MHz FireBug OFF
Opera 10.5: 1.3 MHz
Opera 9.64: 1.2 MHz
Opera 10.10: 1.1 MHz
FF3.6: 0.6 MHz FireBug Console
Chrome5.0.307.9: 0.6 MHz Developer Tools console
FF2.0.0.20: 0.2 MHz FireBug OFF
The source code:
**********************************************
javascript:
var k= 20e6; n= k, v= 0, t= +new Date();
while (n) {
v+= n/2/n;
n--;
}
t= +new Date() -t;
(this.alert || this.print)([(k/t/1e3).toFixed(1)+ " MHz", t+" ms",
v]);
**********************************************
C:
volatile int RUN= 1;
void alrmHandler (int status) {
RUN= 0;
}
int main (int argc, char* argv[]) {
double ctr= 0;
double v= 0;
struct itimerval timer;
timer.it_interval.tv_sec= timer.it_interval.tv_usec= 0;
timer.it_value.tv_usec= 0;
timer.it_value.tv_sec= 1;
signal(SIGALRM, alrmHandler);
setitimer(ITIMER_REAL, &timer, 0);
while (RUN) {
ctr++;
v+= ctr/2/ctr;
}
fprintf(stdout, "%.1f MHz, %.1f\n", ctr/1e6, v);
fflush(stdout);
return 0;
}