One of the really nice features of profiling is that you can compare profiles with one another. If we have two separate measurements from the same program, we can determine whether or not the change we made is having a positive impact on the system. Let's augment our HTTP sleep timing function a little bit:
- Let's add a few extra imports:
package main
import (
"fmt"
"net/http"
_ "net/http/pprof"
"strconv"
"time"
)
- Next, we'll augment our handler to take a query string parameter for time:
func main() {
Handler := func(w http.ResponseWriter, r *http.Request) {
sleepDuration := r.URL.Query().Get("time")
sleepDurationInt, err := strconv.Atoi(sleepDuration)
if err != nil {
fmt.Println("Incorrect value passed as a query string for time...