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