• dpm (cs)

    How did Wayne keep the compiler from simply skipping that code altogether? In 1985, I had a boss who tried to do exactly the same thing for the same reason, but was foiled by the optimizer and never figured out why.

  • GUI Expert (unregistered)

    Say what you want, but this is genious

  • alexgieg (cs)

    Absolutely Brillant!

  • Ravenheart (unregistered) in reply to dpm

    I don't know about back then, but today you can turn the optimization process OFF.

  • Kasper (unregistered)
    Comment held for moderation.
  • Baldric (unregistered)

    God help him if he is ever given a manager who knows his stuff... He'll be out the door so fast your head would spin.

  • flop (unregistered) in reply to dpm
    Comment held for moderation.
  • deezil (unregistered)

    I love how all the typos are still presant in the reposted version.

    CAPTCHA: vindico - Latin for vindicated.

  • nonpartisan (cs) in reply to deezil
    deezil:
    I love how all the typos are still presant in the reposted version.

    CAPTCHA: vindico - Latin for vindicated.

    You can't edit the classics. If you did, then it would be an edited classic and not a classic.

    How well do you think it'd go over if Juliet asked, "Yo Ro, where y'at?"

  • boog (cs)
    “Nothing – and I mean nothing – in IT takes less than 80 hours, and whatever you think it’ll actually take, multiply it by 20, and tell management that. You see, 80/20.”
    I thought the 80/20 rule was that 80% of all programmers are total nit-wits, and if the guy hiring you is one of them you're 20 times more likely to submit his code to this site.
  • Medinoc (unregistered) in reply to dpm
    dpm:
    How did Wayne keep the compiler from simply skipping that code altogether? In 1985, I had a boss who tried to do exactly the same thing for the same reason, but was foiled by the optimizer and never figured out why.
    Maybe he declared
    i
    as
    volatile
    ?

    Also note that for there to be an "obvious integer overflow",

    int
    must be a 16-bit type, so
    i
    's type is probably
    long int
    .

  • boog (cs)
    “The idea is,” Wayne continued, “whenever we have those really slow weeks ... we just drop one of the zeros on the loop. And then we just tell the manager ... we were able to speed things up significantly...”
    Ben should have removed the speed-up loop and taken credit for optimizing the hell out of the application.
  • Medinoc (unregistered) in reply to Medinoc

    Oh that's just great, monospaced text gets its own paragraph. Serves me right for forgetting to preview first.

  • Per (unregistered)

    Is there really an "obvious integer overflow"? Isn't the max value of the

    int
    -type 2147483647?

    And can you really use ++ on a

    char
    -type?

    Sorry for my questions, but I'm still a beginner at programming.

    (Or am I missing the sarcasm in the text? :-p)

  • foo (unregistered)

    I think I know where that guy ended up.

    A while ago I inherited a web application which uses a shitload of server-side web service requests (with a lot of conversion and validation on both ends) to talk to the same application on the same server, where any sane person would simply implement the necessary function calls directly.

    If an average "save customer detail form" action requires over two dozen of those "web service" loopbacks you know it's time to refactor some code.

  • big picture thinker (unregistered) in reply to dpm
    dpm:
    How did Wayne keep the compiler from simply skipping that code altogether? In 1985, I had a boss who tried to do exactly the same thing for the same reason, but was foiled by the optimizer and never figured out why.
    Perhaps the loop was assembly, but just changed to c for ease of reading. The article did say there was some in-line assembly.

    Managers aren't always as stupid as you think and one of them would surely notice that the same, easy-to-read line of c code gets changed on a weekly basis but never removed. It was probably assembly to obfuscate it more.

  • Kef Schecter (unregistered) in reply to nonpartisan
    nonpartisan:
    How well do you think it'd go over if Juliet asked, "Yo Ro, where y'at?"

    Is it weird that I'm bothered less by the modern slang and more by the fact that "wherefore" does not mean "where"?

  • Furiant (unregistered) in reply to deezil
    deezil:
    I love how all the typos are still presant in the reposted version.

    present

  • TGV (cs)

    Nowadays we get these slow downs built in into our frameworks. That's so much easier.

  • Brendan (unregistered) in reply to Per
    Per:
    Is there really an "obvious integer overflow"? Isn't the max value of the
    int
    -type 2147483647?

    It's "implementation defined".

    On 16-bit machines (I'm sure DOS was mentioned in the article somewhere), an int is probably 16-bit and probably ranges from -32768 to +32767.

  • darkmattar (cs) in reply to Per
    Per:
    Is there really an "obvious integer overflow"? Isn't the max value of the
    int
    -type 2147483647?

    And can you really use ++ on a

    char
    -type?

    Sorry for my questions, but I'm still a beginner at programming.

    (Or am I missing the sarcasm in the text? :-p)

    It's a pointer to some memory space defined as Char in size.

    The ++ is supposed to increment the pointer to point to the next location in memory. So what this is probably meant to be do is set 1000000 spots in memory to be equal to 0 starting from 0x10000.

    Unrolling the loop would give something like: 0x10000 = 0; 0x10001 = 0; ... 0xFFFFF = 0;

    1048575 - 65536 = 983039 memory spaces available to zero out before overflow... and the loop goes 1000000 times. I assumed this was the "obvious overflow", not the int declaration.

  • Steve The Pirate (unregistered) in reply to Per
    Per:
    Is there really an "obvious integer overflow"? Isn't the max value of the
    int
    -type 2147483647?

    And can you really use ++ on a

    char
    -type?

    Sorry for my questions, but I'm still a beginner at programming.

    (Or am I missing the sarcasm in the text? :-p)

    1. The max value of

      int
      depends on the architecture.

    2. It is a pointer, and yes.

  • Alnitak (unregistered) in reply to Per

    He's not increment a char (although you can). He's incrementing a pointer to a char.

  • nonpartisan (cs) in reply to Kef Schecter
    Kef Schecter:
    nonpartisan:
    How well do you think it'd go over if Juliet asked, "Yo Ro, where y'at?"

    Is it weird that I'm bothered less by the modern slang and more by the fact that "wherefore" does not mean "where"?

    Although I enjoyed Shakespeare, we're talking the better part of 25 years since I last studied R&J (high school frosh year). It may have been covered, but I don't recall a discussion about the word "wherefore" and what exactly it meant in this context. And it's not a word I use every day.

    But in reviewing the passage, yeah, you're right. Act II, Scene 2, asking him to ignore his family history -- or if he won't, then she will ignore her history so they can be together. First day back to work, anticipating a major run-in with someone from a different team today, less than 6 hours sleep after already having been up late Christmas night . . .

  • boog (cs) in reply to nonpartisan
    nonpartisan:
    Kef Schecter:
    nonpartisan:
    How well do you think it'd go over if Juliet asked, "Yo Ro, where y'at?"
    Is it weird that I'm bothered less by the modern slang and more by the fact that "wherefore" does not mean "where"?
    ...in reviewing the passage, yeah, you're right.
    A more accurate interpretation in modern slang would be something like, "Daaayamn, Romeo! Why y'gotta be tha' way?", which actually isn't any better.
  • Nag-geoff (unregistered)

    Wayne's the kind of genius I would love to have on my team. True genius is only appreciated after it's time has gone.

    I once worked with a manager who wanted to add two columns "Extra1", "Extra2" to every table in the database.

  • Mason Wheeler (cs) in reply to nonpartisan
    nonpartisan:
    deezil:
    I love how all the typos are still presant in the reposted version.

    CAPTCHA: vindico - Latin for vindicated.

    You can't edit the classics. If you did, then it would be an edited classic and not a classic.

    How well do you think it'd go over if Juliet asked, "Yo Ro, where y'at?"

    Yes, because no one has ever made a successful modernized adaptation of Romeo and Juliet or any other of Shakespeare's classics, such as, oh, I don't know, maybe The Taming of the Shrew. Such a thing would never be popular with modern audiences...

  • Argle (cs) in reply to Per
    Per:
    Is there really an "obvious integer overflow"? Isn't the max value of the
    int
    -type 2147483647?

    And can you really use ++ on a

    char
    -type?

    Sorry for my questions, but I'm still a beginner at programming.

    (Or am I missing the sarcasm in the text? :-p)

    From C's perspective is just another integer with the range of -128 to 127, so, sure, ++ works on it just fine.

    The story took place in the 80's, and I don't recall a DOS compiler at the time where int=long by default. If you saw 'int' in the code from the period and for DOS, your overflow would be at 32767.

  • anon5 (unregistered) in reply to Baldric
    God help him if [he is ever given a manager who knows his stuff...

    haha, you are surely imaginative!

  • anon5 (unregistered) in reply to dpm
    dpm:
    How did Wayne keep the compiler from simply skipping that code altogether? In 1985, I had a boss who tried to do exactly the same thing for the same reason, but was foiled by the optimizer and never figured out why.
    In case you can't just turn the optimization off (perhaps it would alert the flying monkeys), the trick is to include something inside the loop so that it has some effect in the program's state, then the compiler wouldn't feel confident about removing it.
  • PiisAWheeL (cs) in reply to anon5
    anon5:
    dpm:
    How did Wayne keep the compiler from simply skipping that code altogether? In 1985, I had a boss who tried to do exactly the same thing for the same reason, but was foiled by the optimizer and never figured out why.
    In case you can't just turn the optimization off (perhaps it would alert the flying monkeys), the trick is to include something inside the loop so that it has some effect in the program's state, then the compiler wouldn't feel confident about removing it.

    There IS something in the loop: ; Does that count?

  • Abso (cs) in reply to Argle
    Argle:
    Per:
    Is there really an "obvious integer overflow"? Isn't the max value of the
    int
    -type 2147483647?

    And can you really use ++ on a

    char
    -type?

    Sorry for my questions, but I'm still a beginner at programming.

    (Or am I missing the sarcasm in the text? :-p)

    From C's perspective is just another integer with the range of -128 to 127, so, sure, ++ works on it just fine.

    The story took place in the 80's, and I don't recall a DOS compiler at the time where int=long by default. If you saw 'int' in the code from the period and for DOS, your overflow would be at 32767.

    It's true that you can use ++ on a char. However, the code fragment shown here doesn't do so. The ++ actually affects the pointer.

    *p++ = 0;
    is the same as
    *(p++) = 0;

    So the effect of this line is to zero the byte p is currently pointing to, and also increment p to point to the next byte.

  • Nag-Geoff (unregistered) in reply to Baldric
    Baldric:
    God help him if he is ever given a manager who knows his stuff... He'll be out the door so fast your head would spin.

    Do you also believe in a) tooth fairy, b) santa claus and c) frozen requirements?

  • someone (unregistered)

    I knew someone who had a shell script that paused for 4 seconds and then printed a "segmentation fault" message.

    Whenever the boss asked about progress, he would put on his baffled look and say "I'm still working on that bug, but I can't find where the crash is... I've been debugging it for days now". Then he would run the script to show the "progress", and say "here, it crashes after the initialisation, but I'm still looking".

    We would just nod our heads in disbelief (but his lack of progress didn't actually affect anyone).

  • baffled (unregistered) in reply to Kef Schecter

    Maybe in real life, but tdwtf has a pretty high bar for weird.

  • nonpartisan (cs) in reply to Mason Wheeler
    Mason Wheeler:

    Yes, because no one has ever made a successful modernized adaptation of Romeo and Juliet or any other of Shakespeare's classics, such as, oh, I don't know, maybe The Taming of the Shrew. Such a thing would never be popular with modern audiences...

    But those are remakes of classics and they exist in and of themselves. I'm saying you can't change a line in "Romeo and Juliet" and have it stay the same, still calling it "Romeo and Juliet." If you even modernized the spelling of the words Shakespeare used, you're changing it because that's not how it was written.

    The original statement was that the spelling wasn't corrected on today's classic WTF. I'm saying that if the spelling were corrected, or the grammar cleaned up, it's no longer a classic.

  • Abso (cs) in reply to nonpartisan
    nonpartisan:
    Mason Wheeler:

    Yes, because no one has ever made a successful modernized adaptation of Romeo and Juliet or any other of Shakespeare's classics, such as, oh, I don't know, maybe The Taming of the Shrew. Such a thing would never be popular with modern audiences...

    But those are remakes of classics and they exist in and of themselves. I'm saying you can't change a line in "Romeo and Juliet" and have it stay the same, still calling it "Romeo and Juliet." If you even modernized the spelling of the words Shakespeare used, you're changing it because that's not how it was written.

    The original statement was that the spelling wasn't corrected on today's classic WTF. I'm saying that if the spelling were corrected, or the grammar cleaned up, it's no longer a classic.

    Modern productions of "Romeo and Juliet" often cut a lot of the play, and still call it "Romeo and Juliet."

  • Jon E. (unregistered)

    The RWTF is they didn't use OS/2 1.1

  • Steve Montague (unregistered) in reply to Mason Wheeler

    Shakespeare would be a good writer if it wasn't for all those cliche's.

  • Will (unregistered) in reply to Steve Montague
    Steve Montague:
    Shakespeare would be a good writer if it wasn't for all those cliche's.

    Speaking of clichés, here's one!

  • MeesterTurner (cs)

    I once (very briefly) worked with a guy who told me he'd put loops like this all over some industrial resource calculator program because the calcs took under a second to run, but he wanted to delay it to "make it look like it was working hard doing something"

  • Zecc (cs) in reply to Furiant
    Furiant:
    deezil:
    I love how all the typos are still presant in the reposted version.

    present

    Ah yes, the inevitable post pointing out the typo, followed by the inevitable post (this one) pointing out that was obviasly intentional.

    Anyway.. I just want to say this: the Speed-up Loop is to optimization what the Classic WTF is to TDWTF.

  • Per (unregistered)

    Thank you all for explaining the int and pointer for me. I didn't know what the * meant in the code, and didn't realize that once upon a time in the 80's a int wasn't the same as a int in the 21th century.

    Thank you all for enlightening me. :-)

  • da Doctah (cs) in reply to Abso
    Abso:
    nonpartisan:
    Mason Wheeler:

    Yes, because no one has ever made a successful modernized adaptation of Romeo and Juliet or any other of Shakespeare's classics, such as, oh, I don't know, maybe The Taming of the Shrew. Such a thing would never be popular with modern audiences...

    But those are remakes of classics and they exist in and of themselves. I'm saying you can't change a line in "Romeo and Juliet" and have it stay the same, still calling it "Romeo and Juliet." If you even modernized the spelling of the words Shakespeare used, you're changing it because that's not how it was written.

    Modern productions of "Romeo and Juliet" often cut a lot of the play, and still call it "Romeo and Juliet."

    Tybalt shot first.

    (And Friar Laurence failed to make the Padua run in under twelve furlongs.)

  • Buffalo (cs) in reply to anon5
    anon5:
    God help him if [he is ever given a manager who knows his stuff...

    haha, you are surely imaginative!

    Your manager can actually understand the code you write. What do you do now?

    Also, this may explain what happened with Vista. They added 0s instead of removing one! Think about it, every new version of Windows is supposed to be the fastest, what easier way to do that than with a speed-up loop? It's best practice!

    da Doctah:
    Tybalt shot first.

    (And Friar Laurence failed to make the Padua run in under twelve furlongs.)

    +1 internets to you, good sir!

  • eric76 (unregistered)

    Back in the 70s, a couple of friends of mine worked as projectionists in an adult movie theater.

    They had a speedup loop of their own.

    Whenever they got a new movie in, they would watch it looking for scenes where they could cut to the next reel of film. On the last showing of the night, they would cut the movie short.

    On a good night, they could reduce an hour of film to about 20 minutes. I've always wondered what the customers thought or if they even noticed.

  • Zylon (cs) in reply to MeesterTurner
    MeesterTurner:
    I once (very briefly) worked with a guy who told me he'd put loops like this all over some industrial resource calculator program because the calcs took under a second to run, but he wanted to delay it to "make it look like it was working hard doing something"
    I remember reading somewhere that recent versions of the venerable HP 12C calculator have a deliberate calculation delay built in to match the response time of the original hardware.
  • SuperBK (unregistered)

    I once encountered code like that for timing delays. Not very portable. On my local system I noticed "wow this code is taking forever", so I took it upon myself to optimize it. It went to the cusomter who had a faster computer and promptly failed.

  • eric76 (unregistered) in reply to SuperBK
    SuperBK:
    I once encountered code like that for timing delays. Not very portable. On my local system I noticed "wow this code is taking forever", so I took it upon myself to optimize it. It went to the cusomter who had a faster computer and promptly failed.

    I used to have some kind of game on one of the old original IBM PCs that depended on processor speed for timing.

    When I got an 80286, I put the game on it and found it to be completely unplayable because human reaction times weren't fast enough to do anything before your game character was knocked off.

  • Abso (cs) in reply to eric76
    eric76:
    SuperBK:
    I once encountered code like that for timing delays. Not very portable. On my local system I noticed "wow this code is taking forever", so I took it upon myself to optimize it. It went to the cusomter who had a faster computer and promptly failed.

    I used to have some kind of game on one of the old original IBM PCs that depended on processor speed for timing.

    When I got an 80286, I put the game on it and found it to be completely unplayable because human reaction times weren't fast enough to do anything before your game character was knocked off.

    I remember having the same problem. I also remember having a utility that "fixed" it, by consuming most of the CPU time.

Leave a comment on “Classic WTF: The Speed-up Loop”

Log In or post as a guest

Replying to comment #:

« Return to Article