| 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 |
|
| 9 |
package foo |
| 10 |
|
| 11 |
const benchmarkNumNodes = 10000 |
| 12 |
|
| 13 |
func 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 |
|
| 26 |
type B interface { |
| 27 |
ResetTimer() |
| 28 |
N() int |
| 29 |
} |
| 30 |
|
| 31 |
type Tx interface { |
| 32 |
} |
| 33 |
|
| 34 |
type Node struct { |
| 35 |
ID string |
| 36 |
} |
| 37 |
|
| 38 |
type MemoryStore struct { |
| 39 |
} |
| 40 |
|
| 41 |
//go:noinline |
| 42 |
func setupNodes(n int) (s *MemoryStore, nodeIDs []string) { |
| 43 |
return |
| 44 |
} |
| 45 |
|
| 46 |
//go:noinline |
| 47 |
func (s *MemoryStore) Update(cb func(Tx) error) error { |
| 48 |
return nil |
| 49 |
} |
| 50 |
|
| 51 |
var sink interface{} |
| 52 |
|
| 53 |
//go:noinline |
| 54 |
func UpdateNode(tx Tx, n *Node) error { |
| 55 |
sink = tx |
| 56 |
sink = n |
| 57 |
return nil |
| 58 |
} |