stopwatch is a small package to easily profile code in go.
go get github.com/XotoX1337/stopwatch
import "github.com/XotoX1337/stopwatch"
watch := stopwatch.New()
section, err := watch.Start("foo")
if err != nil {
fmt.Println(err)
}
//code to profile
section, err = section.Stop("foo")
if err != nil {
fmt.Println(err)
}
fmt.Printf("execution took %s", section.Duration())
import "github.com/XotoX1337/stopwatch"
watch := stopwatch.New()
section, err := watch.Start("foo")
if err != nil {
fmt.Println(err)
}
//code to profile
section.Lap()
//code to profile inside section "foo"
section.Lap()
//additional code to profile inside section "foo"
section, err = section.Stop("foo")
if err != nil {
fmt.Println(err)
}
fmt.Printf("execution took %s", section.Duration())
for i, lap := range section.Laps() {
fmt.Printf("%d. Lap took %s", i+1, lap.Duration())
}