...
Run Format

Source file src/runtime/internal/atomic/bench_test.go

Documentation: runtime/internal/atomic

     1  // Copyright 2016 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package atomic_test
     6  
     7  import (
     8  	"runtime/internal/atomic"
     9  	"testing"
    10  )
    11  
    12  var sink interface{}
    13  
    14  func BenchmarkAtomicLoad64(b *testing.B) {
    15  	var x uint64
    16  	sink = &x
    17  	for i := 0; i < b.N; i++ {
    18  		_ = atomic.Load64(&x)
    19  	}
    20  }
    21  
    22  func BenchmarkAtomicStore64(b *testing.B) {
    23  	var x uint64
    24  	sink = &x
    25  	for i := 0; i < b.N; i++ {
    26  		atomic.Store64(&x, 0)
    27  	}
    28  }
    29  
    30  func BenchmarkAtomicLoad(b *testing.B) {
    31  	var x uint32
    32  	sink = &x
    33  	for i := 0; i < b.N; i++ {
    34  		_ = atomic.Load(&x)
    35  	}
    36  }
    37  
    38  func BenchmarkAtomicStore(b *testing.B) {
    39  	var x uint32
    40  	sink = &x
    41  	for i := 0; i < b.N; i++ {
    42  		atomic.Store(&x, 0)
    43  	}
    44  }
    45  
    46  func BenchmarkXadd(b *testing.B) {
    47  	var x uint32
    48  	ptr := &x
    49  	b.RunParallel(func(pb *testing.PB) {
    50  		for pb.Next() {
    51  			atomic.Xadd(ptr, 1)
    52  		}
    53  	})
    54  }
    55  
    56  func BenchmarkXadd64(b *testing.B) {
    57  	var x uint64
    58  	ptr := &x
    59  	b.RunParallel(func(pb *testing.PB) {
    60  		for pb.Next() {
    61  			atomic.Xadd64(ptr, 1)
    62  		}
    63  	})
    64  }
    65  

View as plain text