Don:
> Are you running it on a Pentium 4? Pentium 4 has *horrific* branch
> misprediction (minimum 24 cycles, 45 uops). No other processor is nearly
> as bad, eg it's 15 cycles on Core2; it was just 4 cycles on PMMX.
Sorry, I am using a Core2 @ 2GHz.
The fixed C code with timings:
#include "std
bearophile wrote:
I have found an interesting small article about optimization, so I've tried the
code in C and D, and I have found strange results (the D code shows timings
opposite of the article).
This is the article, look at the "Branch Prediction" section:
http://www.ddj.com/184405848
The
Kagamin:
> this is incorrect
Thank you for spotting the silly bug, I'll fix it now. (It seems it's more easy
to leave bugs in such kind of code because it does nothing useful).
But note that in both programs:
#define FIRST
static if (1) {
So the first part only is run in both D and C code, not t
You didn't run your code, lol.
if (i % 4 == 1) {
if (i % 4 == 0) {
counter1++;
} else {
counter2++;
}
} else {
if (i % 4 == 2) {
counter3++;
} else {
I have found an interesting small article about optimization, so I've tried the
code in C and D, and I have found strange results (the D code shows timings
opposite of the article).
This is the article, look at the "Branch Prediction" section:
http://www.ddj.com/184405848
The C code:
http://code