4 ms·
Oh come on. 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.o
by Groxx 16y ago
Oh come on.
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...
- FooBarWidget 16y ago-O3 is too smart, it optimizes away the loop and transforms the code into printf(the_result).
- Groxx 16y agoHah, 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?
- bad_user 16y agoYour 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.
- JoachimSchipper 16y ago"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.
- jemfinch 16y agoHe 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?)
- Groxx 16y agoDid you miss the "update" part? That was at least a few hours after my post. And, despite using volatile, it still runs faster.
- Groxx 16y agoApologies 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: real 0m2.209s user 0m2.191s sys 0m0.006s vs real 0m0.020s user 0m0.001s sys 0m0.003s assembly code for gcc -O3 -S simvm.c: https://gist.github.com/710249 https://gist.github.com/710249 Where's the printf(answer)? For comparison, here's the `gcc -S simvm.c` output: https://gist.github.com/710269 https://gist.github.com/710269