Benchmarking Your Tool

Powerful Command-Line Applications in Go — by Ricardo Gerardi (51 / 127)

The Pragmatic Programmers
The Pragmatic Programmers

--

👈 Writing Tests for colStats | TOC | Profiling Your Tool 👉

Before you start thinking about improving the performance of your tools or programs, you first need to determine what the current status is and define a baseline for comparison. For this exercise, we’ll state that performance means how fast the tool takes to process its workload. Perhaps it’s currently good enough, but we may not know. To determine the current state, we need to measure it.

In the Linux/Unix world the quickest way to determine how fast your applications works is by using the time command. The time command executes the application and prints out how long it took to run. For example, to measure how long your tool takes to process data from the two test files in the testdata directory, run this command:

​ ​$ ​​time​​ ​​./colStats​​ ​​-op​​ ​​avg​​ ​​-col​​ ​​3​​ ​​testdata/example.csv​​ ​​testdata/example2.csv​
​ 233.84

​ real 0m0.008s
​ user 0m0.001s
​ sys 0m0.008s

In this example, it took 0.008 seconds to process those two files. The output line starting with real shows the total elapsed time.

This value doesn’t look bad. In fact, if all you’re planning to do with this tool is to process a few small files, then this is good enough and you don’t need to do anything more. But let’s assume that this tool will be used to process performance…

--

--

The Pragmatic Programmers
The Pragmatic Programmers

We create timely, practical books and learning resources on classic and cutting-edge topics to help you practice your craft and accelerate your career.