For that coworker who won’t stop “optimizing” his or her code, I give you my rules of optimization:
- Don’t optimize
- Don’t optimize, I’m serious
- Don’t optimize without benchmarking first
- Don’t benchmark without profiling first
- See rule #1
Edit: A co-worker suggested a step 4.5 of “Take a coffee break”. I don’t like coffee, but I like the spirit of the suggestion.
Chas. Owens, on 2012-04-26 07:43, said:
Shouldn’t profiling be before benchmarking? If a chunk of code isn’t used a lot, speeding it up generally won’t make a bit of difference.
Dave Rolsky, on 2012-04-26 09:36, said:
The rules are meant to be read completely before being applied, rather than being applied before reading the next one.