I'm writing some basic programs that are hard on the CPU -- e.g. find all possible moves, prime numbers, etc. I know that you are encouraged to break main out into different functions but I was wondering if this has any negative impact on overall speed.
Basically, will Code 1 run (slightly) faster or at the same speed as Code 2?
Function calls don't have any significant negative impact on performance except when you misuse them.
For example, if you are calculating Fibonacci numbers, using a recursive solution is a Bad Idea because you have to recalculate the (N-1)th number for every Nth number you find, creating an exponential explosion in function calls == work done.
A well-designed algorithm, even one breaking the problem down into many sub-functions, is nearly always superior.