Efficiency and Performance
Every story has a villain. For developers, that villain is usually time. They must write code in a given time frame and ideally, the code must run as fast as possible. Most of the errors and bugs are a result of fighting with time constraints, both realistic and imaginary ones! So, this chapter is here to help you fight with the second aspect of time: efficiency and performance. For the first aspect of time, you need a good manager with technical skills.
The first part of the chapter is about benchmarking Go code using benchmark functions that measure the performance of a function or an entire program. Thinking that the implementation of a function is faster than a different implementation is not enough. We need to be able to prove it.
After that, we talk about how Go manages memory and how careless Go code can introduce memory leaks. A memory leak in Go occurs when memory that is no longer needed is not properly released, causing the program’...