github.com/haraldrudell/parl@v0.4.176/pruntime/cached-location_bench_test.go (about)

     1  /*
     2  © 2021–present Harald Rudell <harald.rudell@gmail.com> (https://haraldrudell.github.io/haraldrudell/)
     3  ISC License
     4  */
     5  
     6  package pruntime
     7  
     8  import (
     9  	"testing"
    10  )
    11  
    12  // subsequent is 0.6833 ns -99.93%
    13  //   - initial is 1,004 ns
    14  //   - — 0.85 parallel mutex Lock/Unlock 1,178 wall-ns/op
    15  //
    16  // 231126 c66
    17  // Running tool: /opt/homebrew/bin/go test -benchmem -run=^$ -bench ^BenchmarkCachedLocationSuite$ github.com/haraldrudell/parl/pruntime
    18  // goos: darwin
    19  // goarch: arm64
    20  // pkg: github.com/haraldrudell/parl/pruntime
    21  // BenchmarkCachedLocationSuite/Init-10         	 1165704	      1004 ns/op	     456 B/op	       8 allocs/op
    22  // BenchmarkCachedLocationSuite/Cached-10       	1000000000	         0.6833 ns/op	       0 B/op	       0 allocs/op
    23  // PASS
    24  // ok  	github.com/haraldrudell/parl/pruntime	2.969s
    25  func BenchmarkCachedLocationSuite(b *testing.B) {
    26  	var benchs = []struct {
    27  		name  string
    28  		bench func(b *testing.B)
    29  	}{
    30  		{"Init", BenchmarkCachedLocationInit},
    31  		{"Cached", BenchmarkCachedLocation},
    32  	}
    33  	for _, bench := range benchs {
    34  		b.Run(bench.name, bench.bench)
    35  	}
    36  
    37  }
    38  
    39  func BenchmarkCachedLocationInit(b *testing.B) {
    40  	var c CachedLocation
    41  	for i := 0; i < b.N; i++ {
    42  		c = CachedLocation{}
    43  		c.PackFunc()
    44  	}
    45  }
    46  
    47  func BenchmarkCachedLocation(b *testing.B) {
    48  	var c CachedLocation
    49  	c.PackFunc()
    50  	for i := 0; i < b.N; i++ {
    51  		c.PackFunc()
    52  	}
    53  }