From the course: Go Essentials: Concurrency, Connectivity, and High-Performance Apps

Unlock the full course today

Join today to access over 24,000 courses taught by industry experts.

Benchmarking and profiling

Benchmarking and profiling

- [Instructor] One of the advantages of using Go that is a very fast language, but in some cases the code is not fast enough, and then you'd like to measure how fast the code is running, and also to find out where are the bottlenecks or where your code is spending your time. Go provides solution for both of these with the benchmarking and profiling that is built-in with the Go tool. Let's have a look. Say we have a function called tokenize that will return a list of tokens found inside the text. We would like to see how fast it's running and where does it spend its time. Before you start, you'll need to install graphviz, which has the dot utility. You can either install it from the graphviz site or via your package manager. So we write a benchmark. The benchmark is written in a test file that ends with _test.go. We have our bench text that should be similar to average sentences that you are tokenizing. And now…

Contents