Black Lives Matter. Support the Equal Justice Initiative.

Source file src/runtime/norace_test.go

Documentation: runtime

     1  // Copyright 2013 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  // The file contains tests that cannot run under race detector for some reason.
     6  //go:build !race
     7  // +build !race
     8  
     9  package runtime_test
    10  
    11  import (
    12  	"runtime"
    13  	"testing"
    14  )
    15  
    16  // Syscall tests split stack between Entersyscall and Exitsyscall under race detector.
    17  func BenchmarkSyscall(b *testing.B) {
    18  	benchmarkSyscall(b, 0, 1)
    19  }
    20  
    21  func BenchmarkSyscallWork(b *testing.B) {
    22  	benchmarkSyscall(b, 100, 1)
    23  }
    24  
    25  func BenchmarkSyscallExcess(b *testing.B) {
    26  	benchmarkSyscall(b, 0, 4)
    27  }
    28  
    29  func BenchmarkSyscallExcessWork(b *testing.B) {
    30  	benchmarkSyscall(b, 100, 4)
    31  }
    32  
    33  func benchmarkSyscall(b *testing.B, work, excess int) {
    34  	b.SetParallelism(excess)
    35  	b.RunParallel(func(pb *testing.PB) {
    36  		foo := 42
    37  		for pb.Next() {
    38  			runtime.Entersyscall()
    39  			for i := 0; i < work; i++ {
    40  				foo *= 2
    41  				foo /= 2
    42  			}
    43  			runtime.Exitsyscall()
    44  		}
    45  		_ = foo
    46  	})
    47  }
    48  

View as plain text