package main import ( "fmt" "time" "strconv" ) // The pinger prints a ping and waits for a pong func startLog(startTime time.Time, pinger <-chan int) { <-pinger fmt.Println("Start log:") fmt.Println(startTime) } // The ponger prints a pong and waits for a ping func endLog(startTime time.Time, ponger <-chan int) { <-ponger endTime := time.Now() diffTime := endTime.UnixNano() - startTime.UnixNano() fmt.Println("End log: ") fmt.Println(endTime) fmt.Println("Execution time: " + strconv.FormatInt(diffTime, 10) + " nanoseconds") } func startLogThread(startTime time.Time) { ping := make(chan int) go startLog(startTime, ping) ping <- 1 } func endLogThread(startTime time.Time) { pong := make(chan int) go endLog(startTime, pong) pong <- 1 } func main() { startTime := time.Now() fmt.Println("Start test") fmt.Println("") startLogThread(startTime) fmt.Println("") fmt.Println("Function is needed to measure performance => HERE") fmt.Println("") endLogThread(startTime) fmt.Println("") fmt.Println("End test") }
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy. Accept Learn more