github.com/zhongdalu/gf@v1.0.0/g/internal/mutex/mutex_z_bench_test.go (about)

     1  // Copyright 2018 gf Author(https://github.com/zhongdalu/gf). 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/zhongdalu/gf.
     6  
     7  package mutex_test
     8  
     9  import (
    10  	"github.com/zhongdalu/gf/g/internal/mutex"
    11  	"testing"
    12  )
    13  
    14  var (
    15  	safeLock   = mutex.New(false)
    16  	unsafeLock = mutex.New(true)
    17  )
    18  
    19  func Benchmark_Safe_LockUnlock(b *testing.B) {
    20  	for i := 0; i < b.N; i++ {
    21  		safeLock.Lock()
    22  		safeLock.Unlock()
    23  	}
    24  }
    25  
    26  func Benchmark_UnSafe_LockUnlock(b *testing.B) {
    27  	for i := 0; i < b.N; i++ {
    28  		unsafeLock.Lock()
    29  		unsafeLock.Unlock()
    30  	}
    31  }