1
0
mirror of https://github.com/golang/go synced 2024-11-07 14:56:16 -07:00
go/src/runtime/norace_test.go
Russ Cox d4b2638234 all: go fmt std cmd (but revert vendor)
Make all our package sources use Go 1.17 gofmt format
(adding //go:build lines).

Part of //go:build change (#41184).
See https://golang.org/design/draft-gobuild

Change-Id: Ia0534360e4957e58cd9a18429c39d0e32a6addb4
Reviewed-on: https://go-review.googlesource.com/c/go/+/294430
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Jason A. Donenfeld <Jason@zx2c4.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2021-02-20 03:54:50 +00:00

48 lines
996 B
Go

// Copyright 2013 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// The file contains tests that cannot run under race detector for some reason.
//go:build !race
// +build !race
package runtime_test
import (
"runtime"
"testing"
)
// Syscall tests split stack between Entersyscall and Exitsyscall under race detector.
func BenchmarkSyscall(b *testing.B) {
benchmarkSyscall(b, 0, 1)
}
func BenchmarkSyscallWork(b *testing.B) {
benchmarkSyscall(b, 100, 1)
}
func BenchmarkSyscallExcess(b *testing.B) {
benchmarkSyscall(b, 0, 4)
}
func BenchmarkSyscallExcessWork(b *testing.B) {
benchmarkSyscall(b, 100, 4)
}
func benchmarkSyscall(b *testing.B, work, excess int) {
b.SetParallelism(excess)
b.RunParallel(func(pb *testing.PB) {
foo := 42
for pb.Next() {
runtime.Entersyscall()
for i := 0; i < work; i++ {
foo *= 2
foo /= 2
}
runtime.Exitsyscall()
}
_ = foo
})
}