标签:http tar import ima pre nil for nal 好用
package main import ( "fmt" "sync" "time" ) func main() { start := time.Now() mu := sync.Mutex{} for i := 0; i < 1000000; { mu.Lock() i++ mu.Unlock() } fmt.Println(time.Since(start)) start = time.Now() ch := make(chan *bool, 1) for i := 0; i < 1000000; { ch <- nil i++ <-ch } fmt.Println(time.Since(start)) }
曾经听老师说过mutex是比较重量级的锁,channal是轻量级的,所以上锁时最好用channal替代mutex,但试了一下发现mutex比channal快了几倍
标签:http tar import ima pre nil for nal 好用
原文地址:http://www.cnblogs.com/cdyboke/p/7260594.html