package lock_test import ( "sync" "testing" ) func BenchmarkSyncMutex(t *testing.B) { // 100000000 loop // goos: darwin // goarch: amd64 // pkg: git.wecise.com/wecise/mring/z/lock // cpu: Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz // BenchmarkSyncMutex // BenchmarkSyncMutex-8 1 33905064348 ns/op 2407287568 B/op 100034140 allocs/op // PASS // ok git.wecise.com/wecise/mring/z/lock 34.056s // // 10000000 loop // goos: darwin // goarch: amd64 // pkg: git.wecise.com/wecise/mring/z/lock // cpu: Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz // BenchmarkSyncMutex // BenchmarkSyncMutex-8 1 3215950432 ns/op 243519072 B/op 10016404 allocs/op // PASS // ok git.wecise.com/wecise/mring/z/lock 3.980s // // 1000000 loop // goos: darwin // goarch: amd64 // pkg: git.wecise.com/wecise/mring/z/lock // cpu: Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz // BenchmarkSyncMutex // BenchmarkSyncMutex-8 1000000000 0.3031 ns/op 0 B/op 0 allocs/op // PASS // ok git.wecise.com/wecise/mring/z/lock 5.979s var mutex sync.Mutex t.StartTimer() for i := 0; i < 10000000; { go func() { mutex.Lock() i++ mutex.Unlock() }() } t.StopTimer() } func BenchmarkChan(t *testing.B) { // 100000000 loop Crash // // 10000000 loop // goos: darwin // goarch: amd64 // pkg: git.wecise.com/wecise/mring/z/lock // cpu: Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz // BenchmarkChan // BenchmarkChan-8 1 49887892128 ns/op 5246415680 B/op 35689879 allocs/op // PASS // ok git.wecise.com/wecise/mring/z/lock 52.270s // // 1000000 loop // goos: darwin // goarch: amd64 // pkg: git.wecise.com/wecise/mring/z/lock // cpu: Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz // BenchmarkChan // BenchmarkChan-8 1 1749597455 ns/op 313448576 B/op 2504514 allocs/op // PASS // ok git.wecise.com/wecise/mring/z/lock 2.472s ch := make(chan struct{}, 1) t.StartTimer() for i := 0; i < 10000000; { go func() { ch <- struct{}{} i++ <-ch }() } t.StopTimer() }