- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
Admin
Admin
... at least he is honest.
Admin
I'm shocked!
Admin
Turbo C++ 3.0, a 1992 compiler, does not optimize the empty loop!
Admin
You didn't work on Vista, did you?
Admin
"for (i=0; i<10; i++) {;}
would be optimised to NOP x 10 by most compilers set to 'unroll loops'? And would they then remove redundant NOPs? "
Don't forget to set i to 9 as well.
Admin
Admin
And also to Java, javascript, perl, php... anyone else want to add some more? ;^)
Admin
You remember "The first 80% of the project take 20% of your time, the last 20% of the project takes 80% of the time." as the 90/10 rule!?
Admin
You don't save a cycle but some code size. Compilers (and assembler programmers) have used this idiom for a long time to avoid the need for an immediate 0 in the code segment. Basically, when you write
mov eax, N
where N is a constant, the assembler will generate the opcode for "mov eax, (immediate)" followed by N as a 32-bit value. If you even use rax, you get a 64-bit immediate. xor eax, eax however does not require an immediate so results in a much smaller instruction.
Ironically, using xor eax,eax instead of mov eax,0 could actually slow down execution because the false read dependency can stall out-of-order execution as it is used in modern x86 processors. Because the idiom is so widely used, however, processors treat instructions like this as a simple write, thus avoiding this penalty.
By the way, the nop mnemonic in x86 assembler is just an alias for xchg eax,eax (assuming 32-bit operand mode). It, too, is special-cased in the processor to avoid false read and in this case also write dependencies.
Admin
So ... in those days they didn't have optimizing compilers?
Mind you, I was still dabbling in GWBasic back then...
Admin
But C/C++ compile into machine code, everything what is in compiled code will be executed. Isn't C# code optimized on-the-fly like Java in JVM?
Admin
http://blogmiel.blogspot.com/
Surely it compiles into machine code but it can't always be perfectly optimized for every processor out there.
Admin
"I'd rather set it to 10, but if i is not used outside the loop then I would not want it to even exist!"
Sorry, you're right about it being 10. But from the code fragment you can't tell that it's not used outside the loop, but you can tell it is in scope outside the loop (since it's not "for (int i = 0...")
Admin
Actually, the two I know are:
Admin
Hilarous.
Admin
This reminds me of the story on TDWTF about a guy who wrote some scanner software and found a way to speed it up. It was so fast the customer didn't believe the software actually worked because he didn't have to wait, and the programmer had to slow it down. Later he had to speed the software up again.
Admin
well it increments the counter, doen't it?
Admin
Under Windoze, even counting the counters does take soooo much time, but when the counters are actually counting aie, aie, aie
Admin
but when you start wrting into F000 and above the situation changes
Admin
A real-time traveller
Admin
Unless you know how the compiler puts things on the stack. In which case
The above is of course undefined behavior if not outright illegal. I'd have to study to standard to be sure which. Come to think of it I think this is one area where C and C++ are different. Your compiler is likely to pass it though, if only because you told it to shut up.
Admin
It's certainly suspicious code, but it's something to question, not necessarily something to declare a bug.
Admin
Doesn't i cycle between -32768 and 32767? I.e. always less than 1000000. Infinite loops really slow things down.
Admin
The real WTF is that Al Gore hadn't invented the interwebs yet.
Otherwise, hilarious story. Loved it.
Admin
Admin
Did Wayne also invent the Bozo Sort?
Admin
I always thought it meant 80% of the complexity was in 20% of the code. There's probably 1000000 definitions though...
Admin
Admin
Think 16 bit man.
Admin
There is still nothing ethical about it. Whether you are doing actual work on not. There are ways of measuring productivity, other than "the program runs faster"
And on top of that you are writing a Busy Wait loop. Don't do that. Play nice with others and use a Sleep or its equivalent.
Admin
The really hilarious thing is that a lot of modern C compilers will remove the entire for loop, if they can determine that what's inside the loop has no side effects. And {;} certainly has no side effects.
Admin
"Before making any proposal to your boss, insert some decoy steps. The decoys are elements of your plan that you don't actually intend to do. Make sure the decoys are the most obvious parts of your plan." ... "Your boss will notice that the third bullet 'doesn't fit'. He'll demand that you get rid of that step. Put up some resistance (just for show) and then reluctantly agree."
The example he gives is:
Admin
And the best part is any optimizing compiler worth its salt will remove the effects of this "speed-up loop"
Admin
.NET byte code is optimized on-the-fly. This includes C# but also VB.NET, C++/CLI and numerous other languages.
Yes, I love threads where I can show off my super-smartass powers. Just keep that kryptonite away from me.
Admin
"VB.NET, C++/CLI" That makes it sound like C++ and CLI are the same :S
Admin
read back a bit; the conclusion is that it's dependent on the flags and compiler used. GCC doesn't, under any flag.
Admin
Gee and all these years I thought that you figured out the time it would take, divided by two multiplied the result by 4 and added 2. E.G. Task time=((ET/2)*4)+2 Where "ET" equal actual time required.
Admin
Admin
Admin
This is not WTF. This is BOFH.
Admin
It better bloody not. If go to the effort of adding a loop that increments an integer a million times, I bloody well want that integer incremented a million times.
Also, in 1990, most compilers were pretty crappy. In fact, in 2008 most compilers are still pretty crappy.
Admin
And yes, I could look it up, but it's way past my bed-time.
Admin
No, it's the rule that says your program spends 80% of its time in 20% of its code (so that's the code you should optimize). Or, alternatively, 20% of your code will take 80% of your development man-hours (not necessarily the same 20% that accounts for 80% of your run time).
Admin
Three months after November 1989 is January 1990.
Admin
Given a loop like
with a 16-bit compiler, the constant given would not fit in an int and therefore automatically be a long int. That is the rule given in K&R second edition (1988). The comparison would then be done by comparing an extension to long of i with 1000000. Then, variable i would overflow before reaching 1000000, and the loop would be infinite.
Admin
Admin
It is fake: in 1987, a 1 to 1 million loop would take a very very noticeable amount of time (ie: in the seconds magintude order). Having this for each screen refresh ? I call b*s!t.
Anyway, empty loops in screen updating code on early PC were common because you had "snow" effects if you update the screen too frequently...
Admin
That explains SO much. msiexec.exe must be full of these "speedup loops". That's the only thing that can possibly explain why MSI installs are so excruciatingly slow that you want to gouge your eyes out with a sharp object at the thought of running an MSI install.