1 // Copyright 2009 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.
13 func BenchmarkSemaUncontended(b
*testing
.B
) {
14 type PaddedSem
struct {
18 b
.RunParallel(func(pb
*testing
.PB
) {
21 Runtime_Semrelease(&sem
.sem
, false)
22 Runtime_Semacquire(&sem
.sem
)
27 func benchmarkSema(b
*testing
.B
, block
, work
bool) {
33 done
:= make(chan bool)
35 for p
:= 0; p
< runtime
.GOMAXPROCS(0)/2; p
++ {
36 Runtime_Semacquire(&sem
)
44 b
.RunParallel(func(pb
*testing
.PB
) {
47 Runtime_Semrelease(&sem
, false)
49 for i
:= 0; i
< 100; i
++ {
54 Runtime_Semacquire(&sem
)
57 Runtime_Semrelease(&sem
, false)
61 func BenchmarkSemaSyntNonblock(b
*testing
.B
) {
62 benchmarkSema(b
, false, false)
65 func BenchmarkSemaSyntBlock(b
*testing
.B
) {
66 benchmarkSema(b
, true, false)
69 func BenchmarkSemaWorkNonblock(b
*testing
.B
) {
70 benchmarkSema(b
, false, true)
73 func BenchmarkSemaWorkBlock(b
*testing
.B
) {
74 benchmarkSema(b
, true, true)