v8.run/go/exp@v0.0.26-0.20230226010534-afcdbd3f782d/sync2/lock_test.go (about) 1 package sync2_test 2 3 import ( 4 "sync" 5 "testing" 6 ) 7 8 func BenchmarkSyncMutexLockUnlock(b *testing.B) { 9 m := &sync.Mutex{} 10 b.SetBytes(1) 11 b.RunParallel(func(p *testing.PB) { 12 for p.Next() { 13 m.Lock() 14 m.Unlock() 15 } 16 }) 17 } 18 19 func BenchmarkSyncRWMutexLockUnlock(b *testing.B) { 20 m := &sync.RWMutex{} 21 b.SetBytes(1) 22 b.RunParallel(func(p *testing.PB) { 23 for p.Next() { 24 m.Lock() 25 m.Unlock() 26 } 27 }) 28 } 29 30 func BenchmarkSyncRWMutexRLockRUnlock(b *testing.B) { 31 m := &sync.RWMutex{} 32 b.SetBytes(1) 33 b.RunParallel(func(p *testing.PB) { 34 for p.Next() { 35 m.RLock() 36 m.RUnlock() 37 } 38 }) 39 }