Code Testing, Optimization, and Profiling

The previous chapter discussed concurrency in Go and how the select statement allows you to use channels as glue for controlling goroutines and allowing goroutines to communicate.

The Go topics in this chapter are just moderately advanced, yet they are very practical and important, especially when you are interested in improving the performance of your Go programs and discovering bugs quickly. This chapter primarily addresses code optimization, code testing, code documentation, and code profiling.

Code optimization is a process where one or more developers try to make certain parts of a program run faster, more efficient, or use fewer resources. Put simply, code optimization is about eliminating the bottlenecks of a program.

Code testing is about making sure that your code does what you want it to do. In this chapter, you will experience the Go way of testing code. The best time to write code to test your program is during the development phase, as this can help reveal bugs in your code as early as possible.

Code profiling relates to measuring certain aspects of a program in order to get a detailed understanding of the way the code works. The results of code profiling may help you decide which parts of your code need to change.

I hope that you already recognize the importance of documenting your code in order to describe the decisions you made in developing the implementation of your program. In this chapter, you will see how Go can help you generate documentation for the modules that you implement.

Documentation is so important that some developers write the documentation first and the code afterwards!

In this chapter of Mastering Go, you will learn the following topics:

  • Profiling Go code
  • The go tool pprof utility
  • Using the web interface of the Go profiler
  • Testing Go code
  • The go test command
  • The go tool trace utility
  • Benchmarking Go code
  • Cross-compilation
  • Generating documentation for your Go code
  • Creating example functions
  • Finding unreachable Go code in your programs
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.194.57