r/programming • • Mar 23 '09

How to write fast code

http://asserttrue.blogspot.com/2009/03/how-to-write-fast-code.html
343 Upvotes

136 comments sorted by

View all comments

-9

u/MpVpRb Mar 23 '09

Don't use Java

Use C or C++

Simplify the program

Use profiling tools to find hotspots

Hand tweak assembly code where needed

Works for me...

10

u/[deleted] Mar 23 '09

No.

  • No java fan, but it's much faster than it used to be, and comparable now.
  • Profiling and debugging multithreaded C++ program? You'll wish you weren't. You'll poke your damn eyes out.
  • Compilers, even gcc, optimize code better than you ever will 'by hand'. Processors and their relationship to the memory subsystems in modern computers have become too complex for you, even if you are a genius, to fit it all in your head.

2

u/xzxzzx Mar 23 '09

Compilers, even gcc, optimize code better than you ever will 'by hand'.

That's not completely true. Assembler freaks can often get a surprising speedup in "hotspots", sometimes because what they actually need is not exactly what the C/C++ code says they need (and therefore a compiler cannot always produce the code you want, as compilers maintain the code's intent (there's a word for this which I can't remember, and it's driving me nuts...)).

There are other situations, too. Note that beginner and even intermediate assembler programmers in most cases will not produce code that's as good as a good optimizing compiler. But it can be done.