Memory allocation and heap management
Some applications can benefit a lot from optimization. Consider routers, for example, which we'll look at in a later recipe. Fortunately, the tool benchmark suite provides flags to collect a number of memory allocations as well as memory allocation size. It can be helpful to tune certain critical code paths to minimize these two attributes.
This recipe will show two approaches to writing a function that glues together strings with a space, similar to strings.Join("a", "b", "c")
. One approach will use concatenation, while the other will use the strings
package. We'll then compare performance and memory allocations between the two.
Getting ready
Refer to the Getting ready section of the Speeding up compilation and testing cycles recipe in this chapter.
How to do it...
These steps cover writing and running your application:
- From your terminal/console application, create the
chapter13/tuning
directory and navigate to it. - Copy tests from https://github.com/agtorre...