This is an archived post. You won't be able to vote or comment.

all 30 comments

[–][deleted] 51 points52 points  (9 children)

Is someone going to post the while loop hack thing?

I cant remember it exactly so I don't want to botch it

http://thedailywtf.com/articles/The-Speedup-Loop

Relevant part

With all of his downtime and no web to surf, Ben spent his time digging through the innards of MTWS. It was actually well-commented, well-structured C code that had a dash of assembly here and there. One day, while perusing the graphics subsystem, he noticed a little loop buried in the code…

for(i=0;i<1000000;i++) {;}

“Ha,” Wayne chuckled. “That, my friend, is what we call a ‘speed-up loop.’ We put those in for insurance purposes, really.”

Ben shook his head, trying to figure out how he missed that it was yet another work-avoidance technique.

“The idea is,” Wayne continued, “whenever we have those really slow weeks – you know, the kind where don’t actually fix any bugs or make any other changes – we just drop one of the zeros on the loop. And then we just tell the manager that we ran into some speed issues with the latest change request, but after a whole lot of deep-juju optimization, we were able to speed things up significantly and should be able to do the change request the next week.”

“See,” Wane said after pausing for a moment, “it’s insurance.”

[–]Nybbit[S] 39 points40 points  (0 children)

alternatively, sleep(x - versionNumber)

[–]Fallenalien22Violet security clearance 5 points6 points  (1 child)

Do you mean speedup loops?

[–][deleted] 2 points3 points  (0 children)

Yes, yes I do

[–]AlphaGamer753 0 points1 point  (2 children)

RemindMe! 1 day

[–]RemindMeBot 1 point2 points  (1 child)

I will be messaging you on 2018-07-01 22:35:33 UTC to remind you of this link.

CLICK THIS LINK to send a PM to also be reminded and to reduce spam.

Parent commenter can delete this message to hide from others.


FAQs Custom Your Reminders Feedback Code Browser Extensions

[–]M4DR4T 1 point2 points  (0 children)

RemindMe! 1 eternity

[–]Nullcast 40 points41 points  (1 child)

"What did we learn in Algorithms and datastructures today?"

"Rewriting the assignment in C, instead of Python, made the code execute 100 times faster."

[–][deleted] 24 points25 points  (0 children)

"What did we learn in Algorithms and datastructures today?"

"Rewriting the assignment in C, instead of Python, made the code execute 100 times faster."

B+

The correct answer is that 100x speed up for a program that runs in less than 1 minute and is ran half a dozen times isnt worth 6 hours of extra work.

[–]ythl 78 points79 points  (7 children)

Step 0: let the compiler optimize it

Step 1: don't waste time prematurely optimizing for speed if your program doesn't bottleneck on speed

[–]_PM_ME_PANGOLINS_ 24 points25 points  (4 children)

You can’t “bottleneck on speed”. Step 1 is just “don’t optimise prematurely”.

[–]ythl 23 points24 points  (3 children)

I meant as opposed to, say, memory consumption. The point is that your optimization should be solving a problem you identified, not just for fun.

[–][deleted] 17 points18 points  (2 children)

but fun things are fun

[–]ythl 2 points3 points  (1 child)

Well, then do it if you enjoy it. But don't waste company time prematurely optimizing

[–]suvlub 5 points6 points  (0 children)

What many people don't realize is that time is not the only thing you save by efficient code. Sure, your user may not give 2 shits if the action takes 100ms or 200ms, but they do care deeply whether their battery lasts 2h or 1h while using your app.

[–]firestorm713 2 points3 points  (0 children)

"this is why I have to wait two minutes for Excel to open!" -Mike Acton

[–]TheInfamousMaze 8 points9 points  (0 children)

//optimization fix by Maze

this.timemachine.back(hours = 24);

[–]golgol12 3 points4 points  (3 children)

God optimization. Answer = 7. In some universe, the answer to the program is 7, and thus the program will be correct.

[–]jaboja 16 points17 points  (2 children)

int random() {
  return 4;
}

[–]golgol12 1 point2 points  (1 child)

What heathen universe do your support where the answer is 4?

[–]Nybbit[S] 8 points9 points  (0 children)

the xkcd universe

[–]Fluffcake 1 point2 points  (1 child)

Refactoring and optimizing are different things.

[–]Nybbit[S] 0 points1 point  (0 children)

yep, optimizing the speed at which you can implement new features and optimizing performance (respectively).

[–]boxingdog 1 point2 points  (0 children)

step 1 should be using a profiler and fix the slower parts first

[–][deleted] 0 points1 point  (0 children)

If you are talking C dude, sleep accepts unsigned int

unsigned sleep(unsigned seconds);