modernc.org/gc@v1.0.1-0.20240304020402-f0dba7c97c2b/testdata/errchk/test/fixedbugs/issue16008.go (about)

     1  // errorcheck -0 -race
     2  
     3  // Copyright 2016 The Go Authors. All rights reserved.
     4  // Use of this source code is governed by a BSD-style
     5  // license that can be found in the LICENSE file.
     6  
     7  package foo
     8  
     9  const benchmarkNumNodes = 10000
    10  
    11  func BenchmarkUpdateNodeTransaction(b B) {
    12  	s, nodeIDs := setupNodes(benchmarkNumNodes)
    13  	b.ResetTimer()
    14  	for i := 0; i < b.N(); i++ {
    15  		_ = s.Update(func(tx1 Tx) error {
    16  			_ = UpdateNode(tx1, &Node{
    17  				ID: nodeIDs[i%benchmarkNumNodes],
    18  			})
    19  			return nil
    20  		})
    21  	}
    22  }
    23  
    24  type B interface {
    25  	ResetTimer()
    26  	N() int
    27  }
    28  
    29  type Tx interface {
    30  }
    31  
    32  type Node struct {
    33  	ID string
    34  }
    35  
    36  type MemoryStore struct {
    37  }
    38  
    39  // go:noinline
    40  func setupNodes(n int) (s *MemoryStore, nodeIDs []string) {
    41  	return
    42  }
    43  
    44  //go:noinline
    45  func (s *MemoryStore) Update(cb func(Tx) error) error {
    46  	return nil
    47  }
    48  
    49  var sink interface{}
    50  
    51  //go:noinline
    52  func UpdateNode(tx Tx, n *Node) error {
    53  	sink = tx
    54  	sink = n
    55  	return nil
    56  }