gcc simvm.c
time ./a.out
857419840
real 0m0.374s
user 0m0.359s
sys 0m0.003s
meanwhile:
gcc -O3 simvm.c -o fast.out
time ./fast.out
857419840
real 0m0.006s
user 0m0.001s
sys 0m0.003s
Comparing optimized compiled code against unoptimized compiled code is worthless. .NET does some optimizations as it runs, and JITs, your standard `gcc` does very few.
/me goes to comment on the blog.
edit: bah! Foiled!
>Hmmm, your comment seems a bit spammy. We're not real big on spam around here.
Please go back and try again.
edit2: holy cow, that spam filter hates me. I can't get anything to post...
Hah, nice. Didn't check the resulting code. Know what the other optimization levels do? I'm don't really know x86 assembler.
I do still side with the optimization though, in that the .NET-VM could do this as well. The loop is pretty simple, and can be optimized away. Why shouldn't it?
Your answer received lots of votes for what are basically assumptions.
The author of the article updated his post for -O3 by using a volatile variable for the for-loop test, which makes the compiler not optimize away the loop.
For .NET you can look at the generated assembly, and if it does optimize away the loop you can use the same trick.
No reasons for guessing. We are software engineers after all.
"volatile" forces the C compiler to issue load and store instructions for each access (although real-world C compilers are notoriously buggy here), so it makes the loop much slower. That's not a fair comparison.
He wasn't trying to write something faster than C, he was just establishing a good baseline. He makes that clear in the article when he specifically addresses the fact that compiling with optimizations removes the loops.
(I wonder, did the people who upvoted you actually read the article?)
Apologies on the first results, simvm.c had mistakenly not compiled, so those were the original loops. I had to modify the code to get it to compile (dropped it to "#define LONG") and here are the results:
/me goes to comment on the blog.
edit: bah! Foiled!
>Hmmm, your comment seems a bit spammy. We're not real big on spam around here.
Please go back and try again.
edit2: holy cow, that spam filter hates me. I can't get anything to post...