How to write fast code

Monday, March 23rd, 2009

Kas Thomas shares some advice he received early in his programming career on how to write fast code:

“The CPU,” he said, “runs at a certain speed. It can execute a fixed number of instructions per second, and no more. There is a finite limit to how many instructions per second it can execute. Right?”

“Right,” I said.

“So there is no way, really, to make code go faster, because there is no way to make instructions execute faster. There is only such a thing as making the machine do less.”

He paused for emphasis.

“To go fast,” he said slowly, “do less.”

To go fast, do less. Do less; go fast. Yes, of course. It makes perfect sense. There’s no other way to make a program run faster except to make it do less.

Leave a Reply