diff options
Diffstat (limited to 'src/cmd/compile/internal/test/testdata')
| -rw-r--r-- | src/cmd/compile/internal/test/testdata/pgo/inline/inline_hot.go | 86 | ||||
| -rw-r--r-- | src/cmd/compile/internal/test/testdata/pgo/inline/inline_hot.pprof | bin | 0 -> 1423 bytes | |||
| -rw-r--r-- | src/cmd/compile/internal/test/testdata/pgo/inline/inline_hot_test.go | 47 |
3 files changed, 133 insertions, 0 deletions
diff --git a/src/cmd/compile/internal/test/testdata/pgo/inline/inline_hot.go b/src/cmd/compile/internal/test/testdata/pgo/inline/inline_hot.go new file mode 100644 index 0000000000..c1d2a53983 --- /dev/null +++ b/src/cmd/compile/internal/test/testdata/pgo/inline/inline_hot.go @@ -0,0 +1,86 @@ +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// WARNING: Please avoid updating this file. If this file needs to be updated, then a new inline_hot.pprof file should be generated via "go test -bench=. -cpuprofile testdata/pgo/inline/inline_hot.pprof cmd/compile/internal/test/testdata/pgo/inline". +package main + +import ( + "time" +) + +type BS struct { + length uint + s []uint64 +} + +const wSize = uint(64) +const lWSize = uint(6) + +func D(i uint) int { + return int((i + (wSize - 1)) >> lWSize) +} + +func N(length uint) (bs *BS) { + bs = &BS{ + length, + make([]uint64, D(length)), + } + + return bs +} + +func (b *BS) S(i uint) *BS { + b.s[i>>lWSize] |= 1 << (i & (wSize - 1)) + return b +} + +var jn = [...]byte{ + 0, 1, 56, 2, 57, 49, 28, 3, 61, 58, 42, 50, 38, 29, 17, 4, + 62, 47, 59, 36, 45, 43, 51, 22, 53, 39, 33, 30, 24, 18, 12, 5, + 63, 55, 48, 27, 60, 41, 37, 16, 46, 35, 44, 21, 52, 32, 23, 11, + 54, 26, 40, 15, 34, 20, 31, 10, 25, 14, 19, 9, 13, 8, 7, 6, +} + +func T(v uint64) uint { + return uint(jn[((v&-v)*0x03f79d71b4ca8b09)>>58]) +} + +func (b *BS) NS(i uint) (uint, bool) { + x := int(i >> lWSize) + if x >= len(b.s) { + return 0, false + } + w := b.s[x] + w = w >> (i & (wSize - 1)) + if w != 0 { + return i + T(w), true + } + x = x + 1 + for x < len(b.s) { + if b.s[x] != 0 { + return uint(x)*wSize + T(b.s[x]), true + } + x = x + 1 + + } + return 0, false +} + +func A() { + s := N(100000) + for i := 0; i < 1000; i += 30 { + s.S(uint(i)) + } + for j := 0; j < 1000; j++ { + c := uint(0) + for i, e := s.NS(0); e; i, e = s.NS(i + 1) { + c++ + } + } +} + +func main() { + time.Sleep(time.Second) + A() +} diff --git a/src/cmd/compile/internal/test/testdata/pgo/inline/inline_hot.pprof b/src/cmd/compile/internal/test/testdata/pgo/inline/inline_hot.pprof Binary files differnew file mode 100644 index 0000000000..45ccb6132b --- /dev/null +++ b/src/cmd/compile/internal/test/testdata/pgo/inline/inline_hot.pprof diff --git a/src/cmd/compile/internal/test/testdata/pgo/inline/inline_hot_test.go b/src/cmd/compile/internal/test/testdata/pgo/inline/inline_hot_test.go new file mode 100644 index 0000000000..024d340785 --- /dev/null +++ b/src/cmd/compile/internal/test/testdata/pgo/inline/inline_hot_test.go @@ -0,0 +1,47 @@ +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// WARNING: Please avoid updating this file. If this file needs to be updated, then a new inline_hot.pprof file should be generated via "go test -bench=. -cpuprofile testdata/pgo/inline/inline_hot.pprof cmd/compile/internal/test/testdata/pgo/inline". +package main + +import "testing" + +func BenchmarkA(b *testing.B) { + benchmarkB(b) +} +func benchmarkB(b *testing.B) { + + for i := 0; true; { + A() + i = i + 1 + if i >= b.N { + break + } + A() + i = i + 1 + if i >= b.N { + break + } + A() + i = i + 1 + if i >= b.N { + break + } + A() + i = i + 1 + if i >= b.N { + break + } + A() + i = i + 1 + if i >= b.N { + break + } + A() + i = i + 1 + if i >= b.N { + break + } + } +} |
