github.com/gogf/gf@v1.16.9/os/gmlock/gmlock_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/gogf/gf. 6 7 package gmlock_test 8 9 import ( 10 "github.com/gogf/gf/os/gmlock" 11 "testing" 12 ) 13 14 var ( 15 lockKey = "This is the lock key for gmlock." 16 ) 17 18 func Benchmark_GMLock_Lock_Unlock(b *testing.B) { 19 for i := 0; i < b.N; i++ { 20 gmlock.Lock(lockKey) 21 gmlock.Unlock(lockKey) 22 } 23 } 24 25 func Benchmark_GMLock_RLock_RUnlock(b *testing.B) { 26 for i := 0; i < b.N; i++ { 27 gmlock.RLock(lockKey) 28 gmlock.RUnlock(lockKey) 29 } 30 } 31 32 func Benchmark_GMLock_TryLock_Unlock(b *testing.B) { 33 for i := 0; i < b.N; i++ { 34 if gmlock.TryLock(lockKey) { 35 gmlock.Unlock(lockKey) 36 } 37 } 38 } 39 40 func Benchmark_GMLock_TryRLock_RUnlock(b *testing.B) { 41 for i := 0; i < b.N; i++ { 42 if gmlock.TryRLock(lockKey) { 43 gmlock.RUnlock(lockKey) 44 } 45 } 46 }