Another key topic in the world of testing software is benchmarking. Benchmarking is the practice of measuring the performance of your code. The Go testing package offers you the ability to perform strong benchmarking on your code.
Let's start by targeting a piece of code and showcase how to benchmark it using Go. A good function to benchmark is the hashpassword() function, which is utilized by our database layer. This function can be found in the backend/src/dblayer/orm.go file. It takes a reference to a string as an argument, and then it uses a bcrypt hash to hash the string. Here is the code:
func hashPassword(s *string) error {
if s == nil {
return errors.New("Reference provided for hashing password is nil")
}
//converd password string to byte slice
sBytes := []byte(*s)
//Obtain hashed password
hashedBytes, err := bcrypt.GenerateFromPassword...