github.com/wangyougui/gf/v2@v2.6.5/internal/rwmutex/rwmutex_z_bench_test.go (about) 1 // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 // 3 // This Source Code Form is subject to the terms of the MIT License. 4 // If a copy of the MIT was not distributed with this file, 5 // You can obtain one at https://github.com/wangyougui/gf. 6 7 package rwmutex_test 8 9 import ( 10 "testing" 11 12 "github.com/wangyougui/gf/v2/internal/rwmutex" 13 ) 14 15 var ( 16 safeLock = rwmutex.New(true) 17 unsafeLock = rwmutex.New(false) 18 ) 19 20 func Benchmark_Safe_LockUnlock(b *testing.B) { 21 for i := 0; i < b.N; i++ { 22 safeLock.Lock() 23 safeLock.Unlock() 24 } 25 } 26 27 func Benchmark_Safe_RLockRUnlock(b *testing.B) { 28 for i := 0; i < b.N; i++ { 29 safeLock.RLock() 30 safeLock.RUnlock() 31 } 32 } 33 34 func Benchmark_UnSafe_LockUnlock(b *testing.B) { 35 for i := 0; i < b.N; i++ { 36 unsafeLock.Lock() 37 unsafeLock.Unlock() 38 } 39 } 40 41 func Benchmark_UnSafe_RLockRUnlock(b *testing.B) { 42 for i := 0; i < b.N; i++ { 43 unsafeLock.RLock() 44 unsafeLock.RUnlock() 45 } 46 }