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

     1  // Copyright 2025 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  //go:build cgo
     6  
     7  package cgobench_test
     8  
     9  import (
    10  	"internal/runtime/cgobench"
    11  	"testing"
    12  )
    13  
    14  func BenchmarkCall(b *testing.B) {
    15  	for b.Loop() {
    16  		cgobench.Empty()
    17  	}
    18  }
    19  
    20  func BenchmarkCallParallel(b *testing.B) {
    21  	b.RunParallel(func(pb *testing.PB) {
    22  		for pb.Next() {
    23  			cgobench.Empty()
    24  		}
    25  	})
    26  }
    27  
    28  func BenchmarkCgoCall(b *testing.B) {
    29  	for b.Loop() {
    30  		cgobench.EmptyC()
    31  	}
    32  }
    33  
    34  func BenchmarkCgoCallParallel(b *testing.B) {
    35  	b.RunParallel(func(pb *testing.PB) {
    36  		for pb.Next() {
    37  			cgobench.EmptyC()
    38  		}
    39  	})
    40  }
    41  
    42  func BenchmarkCgoCallWithCallback(b *testing.B) {
    43  	for b.Loop() {
    44  		cgobench.CallbackC()
    45  	}
    46  }
    47  
    48  func BenchmarkCgoCallParallelWithCallback(b *testing.B) {
    49  	b.RunParallel(func(pb *testing.PB) {
    50  		for pb.Next() {
    51  			cgobench.CallbackC()
    52  		}
    53  	})
    54  }
    55  

View as plain text