package main
import (
"fmt"
"sync"
"time"
)
func main() {
t := time.NewTimer(3 * time.Second)
fmt.Printf("Start waiting at %v\n", time.Now().Format(time.UnixDate))
<-t.C
fmt.Printf("Code executed at %v\n", time.Now().Format(time.UnixDate))
wg := &sync.WaitGroup{}
wg.Add(1)
fmt.Printf("Start waiting for AfterFunc at %v\n", time.Now().Format(time.UnixDate))
time.AfterFunc(3*time.Second, func() {
fmt.Printf("Code executed for AfterFunc at %v\n", time.Now().Format(time.UnixDate))
wg.Done()
})
wg.Wait()
fmt.Printf("Waiting on time.After at %v\n", time.Now().Format(time.UnixDate))
<-time.After(3 * time.Second)
fmt.Printf("Code resumed at %v\n", time.Now().Format(time.UnixDate))
}
/*
Start waiting at Thu Mar 22 00:32:42 CST 2018
Code executed at Thu Mar 22 00:32:45 CST 2018
Start waiting for AfterFunc at Thu Mar 22 00:32:45 CST 2018
Code executed for AfterFunc at Thu Mar 22 00:32:48 CST 2018
Waiting on time.After at Thu Mar 22 00:32:48 CST 2018
Code resumed at Thu Mar 22 00:32:51 CST 2018
*/
3.10 计算代码运行的时长
Posted cucy
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了3.10 计算代码运行的时长相关的知识,希望对你有一定的参考价值。
以上是关于3.10 计算代码运行的时长的主要内容,如果未能解决你的问题,请参考以下文章