github.com/wangyougui/gf/v2@v2.6.5/internal/mutex/mutex_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 mutex_test
     8  
     9  import (
    10  	"testing"
    11  
    12  	"github.com/wangyougui/gf/v2/internal/mutex"
    13  )
    14  
    15  var (
    16  	safeLock   = mutex.New(false)
    17  	unsafeLock = mutex.New(true)
    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_UnSafe_LockUnlock(b *testing.B) {
    28  	for i := 0; i < b.N; i++ {
    29  		unsafeLock.Lock()
    30  		unsafeLock.Unlock()
    31  	}
    32  }