github.com/loov/hrtime@v1.0.3/hrtesting/benchmark_test.go (about)

     1  package hrtesting_test
     2  
     3  import (
     4  	"fmt"
     5  	"runtime"
     6  	"testing"
     7  
     8  	"github.com/loov/hrtime/hrtesting"
     9  )
    10  
    11  func BenchmarkReport(b *testing.B) {
    12  	bench := hrtesting.NewBenchmark(b)
    13  	defer bench.Report()
    14  
    15  	for bench.Next() {
    16  		r := fmt.Sprintf("hello, world %d", 123)
    17  		runtime.KeepAlive(r)
    18  	}
    19  }
    20  
    21  func BenchmarkTSCReport(b *testing.B) {
    22  	bench := hrtesting.NewBenchmarkTSC(b)
    23  	defer bench.Report()
    24  
    25  	for bench.Next() {
    26  		r := fmt.Sprintf("hello, world %d", 123)
    27  		runtime.KeepAlive(r)
    28  	}
    29  }