├── http
├── .gitignore
└── http.go
├── json
├── .gitignore
└── json.go
├── garbage
├── .gitignore
└── garbage.go
├── codereview.cfg
├── sweet
├── .gitignore
├── benchmarks
│ ├── biogo-krishna
│ │ ├── README.md
│ │ └── krishna.go
│ ├── bleve-index
│ │ ├── README.md
│ │ └── main.go
│ ├── biogo-igor
│ │ ├── README.md
│ │ └── igor.go
│ ├── internal
│ │ ├── driver
│ │ │ ├── mem.go
│ │ │ └── mem_linux.go
│ │ ├── par
│ │ │ └── funcs.go
│ │ ├── pool
│ │ │ ├── pool_test.go
│ │ │ └── pool.go
│ │ ├── cgroups
│ │ │ └── cgroups.go
│ │ └── server
│ │ │ └── server.go
│ ├── gvisor
│ │ ├── startup.go
│ │ ├── syscall.go
│ │ ├── common.go
│ │ └── main.go
│ ├── tile38
│ │ └── README.md
│ ├── markdown
│ │ └── main.go
│ └── gopher-lua
│ │ └── main.go
├── common
│ ├── version.go
│ ├── generator.go
│ ├── platforms.go
│ ├── diagnostics
│ │ └── driver.go
│ ├── profile
│ │ └── profile.go
│ ├── env.go
│ ├── config_test.go
│ ├── log
│ │ └── log.go
│ ├── gotool.go
│ ├── env_test.go
│ ├── fileutil
│ │ └── copy.go
│ └── harness.go
├── source-assets
│ └── gvisor
│ │ ├── http
│ │ ├── README.md
│ │ └── server.go
│ │ └── syscall
│ │ ├── syscall-bench.go
│ │ └── README.md
├── generators
│ └── none.go
├── cmd
│ └── sweet
│ │ ├── main.go
│ │ ├── get_nocipd.go
│ │ ├── get.go
│ │ ├── benchmark_test.go
│ │ ├── put.go
│ │ └── get_cipd.go
├── cli
│ ├── assets
│ │ ├── version.go
│ │ └── cache.go
│ └── subcommands
│ │ └── sc.go
└── harnesses
│ ├── gvisor.go
│ ├── common.go
│ ├── tile38.go
│ ├── local.go
│ ├── esbuild.go
│ └── etcd.go
├── cmd
├── bent
│ ├── scripts
│ │ ├── localfix-intelbox-1
│ │ ├── localfix-odroid-n2
│ │ ├── localfix-odroid-c2
│ │ ├── benchtime
│ │ ├── bar
│ │ ├── foo
│ │ ├── make_assets
│ │ ├── memprofile
│ │ ├── tmpclr
│ │ ├── cpuprofile
│ │ ├── tweet-results
│ │ ├── cmpcl-phase.sh
│ │ ├── benchdwarf
│ │ ├── cmpjob.sh
│ │ ├── benchsize
│ │ └── cmpcl.sh
│ ├── configs
│ │ ├── configurations-pgo.toml
│ │ ├── configurations-sample.toml
│ │ ├── configurations-gollvm.toml
│ │ ├── configurations-cmpjob.toml
│ │ ├── benchmarks-gc.toml
│ │ ├── benchmarks-gcplus.toml
│ │ ├── configurations-random.toml
│ │ ├── configurations-cronjob.toml
│ │ └── benchmarks-50.toml
│ ├── patches
│ │ ├── ethereum_core
│ │ └── ericlagergren_decimal
│ ├── CONTRIBUTING.md
│ ├── LICENSE
│ └── bent_test.go
└── bench
│ ├── idle_other.go
│ ├── idle_linux.go
│ ├── gotest.go
│ └── bent.go
├── .gitignore
├── third_party
├── bleve-bench
│ ├── README.md
│ └── mapping.go
└── biogo-examples
│ ├── README.md
│ ├── krishna
│ ├── write.go
│ ├── packseqs.go
│ └── krishna.go
│ ├── igor
│ ├── igor
│ │ ├── write.go
│ │ └── pile.go
│ └── turner
│ │ └── cluster.go
│ └── LICENSE
├── driver
├── driver_go10.go
├── driver_go12.go
├── driver_wasm.go
├── driver_stub.go
├── driver_go15.go
├── driver_darwin.go
├── driver_plan9.go
├── driver_unix.go
└── driver_linux.go
├── gc_latency
├── main.go
└── latency_test.go
├── CONTRIBUTING.md
├── PATENTS
├── stats
├── itree_test.go
├── itree.go
├── edm_test.go
└── edmx.go
├── LICENSE
├── README
└── go.mod
/http/.gitignore:
--------------------------------------------------------------------------------
1 | /http
2 |
--------------------------------------------------------------------------------
/json/.gitignore:
--------------------------------------------------------------------------------
1 | /json
2 |
--------------------------------------------------------------------------------
/garbage/.gitignore:
--------------------------------------------------------------------------------
1 | /garbage
2 |
--------------------------------------------------------------------------------
/codereview.cfg:
--------------------------------------------------------------------------------
1 | issuerepo: golang/go
2 |
--------------------------------------------------------------------------------
/sweet/.gitignore:
--------------------------------------------------------------------------------
1 | *.toml
2 | results/
3 |
--------------------------------------------------------------------------------
/cmd/bent/scripts/localfix-intelbox-1:
--------------------------------------------------------------------------------
1 | BUILDER_TYPE="Xeon-E5-1650v3@3.5Ghz*12"
2 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Add no patterns to .hgignore except for files generated by the build.
2 | last-change
3 |
--------------------------------------------------------------------------------
/cmd/bent/scripts/localfix-odroid-n2:
--------------------------------------------------------------------------------
1 | NUMACTL='numactl -C 2-5 --'
2 | export GOMAXPROCS=4
3 | B=3
4 | N=15
5 | BUILDER_TYPE="Odroid-N2-arm64"
6 |
--------------------------------------------------------------------------------
/cmd/bent/scripts/localfix-odroid-c2:
--------------------------------------------------------------------------------
1 | B=3
2 | N=15
3 | BUILDER_TYPE="Odroid-C2-arm"
4 | export BENTARCH="arm" # referenced in configurations-cronjob.toml
5 |
--------------------------------------------------------------------------------
/cmd/bent/scripts/benchtime:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # Run args as command, but with a benchtime parameter
3 |
4 | bt="$1"
5 | shift
6 |
7 | "$@" -test.benchtime="$bt"
8 |
--------------------------------------------------------------------------------
/third_party/bleve-bench/README.md:
--------------------------------------------------------------------------------
1 | # bleve-bench
2 |
3 | This directory contains code derived from the
4 | [bleve-bench](https://github.com/blevesearch/bleve-bench) repository.
5 |
--------------------------------------------------------------------------------
/sweet/benchmarks/biogo-krishna/README.md:
--------------------------------------------------------------------------------
1 | # biogo-krishna Benchmark
2 |
3 | This directory contains a benchmark which runs a Go implementation of PALS,
4 | powered by the biogo bioinformatics library.
5 |
--------------------------------------------------------------------------------
/cmd/bent/scripts/bar:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # Run args as command, but wrapped in bar.
3 | echo Bar bar bar bar bar bar bar
4 | echo Bar args are "$@"
5 | echo Bar environment is
6 | printenv
7 | "$@"
8 | echo ${BENT_BINARY} rab rab rab rab rab rab raB
9 |
--------------------------------------------------------------------------------
/sweet/common/version.go:
--------------------------------------------------------------------------------
1 | // Copyright 2021 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package common
6 |
7 | const Version = "v0.3.0"
8 |
--------------------------------------------------------------------------------
/third_party/biogo-examples/README.md:
--------------------------------------------------------------------------------
1 | # biogo-examples
2 |
3 | This directory contains modified examples from the [biogo examples
4 | repository](https://github.com/biogo/examples). It retains the [BSD-3-clause
5 | license](./LICENSE) associated.
6 |
--------------------------------------------------------------------------------
/cmd/bent/scripts/foo:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # Run args as command, but wrapped in foo.
3 | echo Foo foo foo foo foo foo foo ${BENT_BINARY}
4 | echo Foo args are "$@"
5 | echo Foo environment is
6 | printenv
7 | "$@"
8 | echo ${BENT_BINARY} oof oof oof oof oof oof ooF
9 |
--------------------------------------------------------------------------------
/cmd/bent/scripts/make_assets:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | go-bindata -o assets.go foo memprofile cpuprofile tmpclr benchtime benchsize benchdwarf cronjob.sh cmpjob.sh cmpcl.sh cmpcl-phase.sh tweet-results benchmarks-{all,50,gc,gcplus,trial}.toml configurations-{sample,gollvm,cronjob,cmpjob}.toml
3 |
--------------------------------------------------------------------------------
/cmd/bent/scripts/memprofile:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # Run args as command, but run memprofile and then pprof to capture test memprofile output
3 | mpf="${BENT_PROFILES}/${BENT_BINARY}_${BENT_I}.mprof"
4 | mkdir -p ${BENT_PROFILES}
5 |
6 | "$@" -test.memprofile="$mpf"
7 | echo memprofile in "$mpf"
8 | go tool pprof --alloc_space --text --cum --nodecount=20 "$mpf"
9 |
--------------------------------------------------------------------------------
/cmd/bench/idle_other.go:
--------------------------------------------------------------------------------
1 | // Copyright 2021 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | //go:build !linux
6 |
7 | package main
8 |
9 | // waitForIdle is only implemented for Linux.
10 | func waitForIdle() error {
11 | return nil
12 | }
13 |
--------------------------------------------------------------------------------
/sweet/source-assets/gvisor/http/README.md:
--------------------------------------------------------------------------------
1 | # gVisor HTTP Server Benchmark
2 |
3 | The purpose of this benchmark is to measure the performance of gVisor's
4 | networking stack and VFS layer. It is loosely based on the HTTP
5 | benchmark found in the [gVisor
6 | repository](https://github.com/google/gvisor/blob/3ad6d3056371b031fb0c16c4e365d5c7e60bdaf0/benchmarks/suites/http.py#L115).
7 |
--------------------------------------------------------------------------------
/cmd/bent/configs/configurations-pgo.toml:
--------------------------------------------------------------------------------
1 | [[Configurations]]
2 | Name = "pgo-generate"
3 | Root = "$HOME/work/go/"
4 | PgoGen = "profiles" # Sub-directory where we put profiles
5 | Disabled = true # Request this explicitly
6 |
7 | [[Configurations]]
8 | Name = "pgo-use"
9 | Root = "$HOME/work/go/"
10 | PgoUse = "profiles" # Sub-directory where we search profiles
11 |
--------------------------------------------------------------------------------
/sweet/source-assets/gvisor/syscall/syscall-bench.go:
--------------------------------------------------------------------------------
1 | // Copyright 2021 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package main
6 |
7 | import "os"
8 |
9 | var ppid int
10 |
11 | func main() {
12 | for i := 0; i < 500000; i++ {
13 | ppid = os.Getppid()
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/driver/driver_go10.go:
--------------------------------------------------------------------------------
1 | // Copyright 2013 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | //go:build !go1.2
6 |
7 | package driver
8 |
9 | import (
10 | "runtime"
11 | )
12 |
13 | // New mem stats added in Go1.2
14 | func collectGo12MemStats(res *Result, mstats0, mstats1 *runtime.MemStats) {
15 | }
16 |
--------------------------------------------------------------------------------
/cmd/bent/scripts/tmpclr:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # This wrapper attempts to clean up after benchmarks that dribble files into /tmp
3 | # Some of them respect TMPDIR, some do not.
4 | # The value of BENT_BINARY is not especially likely to match things normally found in /tmp
5 | PID=$$
6 | TD=/tmp/bent-${PID}
7 | mkdir -p ${TD}
8 | TMPDIR=${TD} "$@"
9 | rm -rf ${TD}
10 | if [ "x${BENT_BINARY}" != "x" ] ; then
11 | rm -rf /tmp/${BENT_BINARY}*
12 | fi
13 |
--------------------------------------------------------------------------------
/sweet/benchmarks/bleve-index/README.md:
--------------------------------------------------------------------------------
1 | # bleve-index Benchmark
2 |
3 | This directory contains a benchmark that indexes a small subset of Wikipedia
4 | into a Bleve search index.
5 |
6 | The benchmark is a based loosely on the benchmark contained within the
7 | [bleve-bench](https://github.com/blevesearch/bleve-bench) repository.
8 | The parts that were derived from bleve-bench may be found
9 | [here](../../third_party/bleve-bench/README.md).
10 |
--------------------------------------------------------------------------------
/sweet/generators/none.go:
--------------------------------------------------------------------------------
1 | // Copyright 2021 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package generators
6 |
7 | import "golang.org/x/benchmarks/sweet/common"
8 |
9 | // None is a Generator that does nothing.
10 | type None struct{}
11 |
12 | // Generate does nothing.
13 | func (None) Generate(_ *common.GenConfig) error {
14 | return nil
15 | }
16 |
--------------------------------------------------------------------------------
/sweet/cmd/sweet/main.go:
--------------------------------------------------------------------------------
1 | // Copyright 2021 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package main
6 |
7 | import (
8 | "os"
9 |
10 | "golang.org/x/benchmarks/sweet/cli/subcommands"
11 | )
12 |
13 | func main() {
14 | subcommands.Register(&getCmd{})
15 | subcommands.Register(&putCmd{})
16 | subcommands.Register(&runCmd{})
17 | subcommands.Register(&genCmd{})
18 | os.Exit(subcommands.Run())
19 | }
20 |
--------------------------------------------------------------------------------
/sweet/cmd/sweet/get_nocipd.go:
--------------------------------------------------------------------------------
1 | // Copyright 2021 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | //go:build wasm || plan9
6 |
7 | package main
8 |
9 | import (
10 | "errors"
11 |
12 | "golang.org/x/benchmarks/sweet/common/log"
13 | )
14 |
15 | func (c *getCmd) Run(_ []string) error {
16 | log.SetActivityLog(true)
17 | return errors.New("get unsupported on this platform: CIPD not supported on this platform")
18 | }
19 |
--------------------------------------------------------------------------------
/cmd/bent/configs/configurations-sample.toml:
--------------------------------------------------------------------------------
1 | [[Configurations]]
2 | Name = "Control"
3 | RunEnv = ["GOGC=100"]
4 | RunFlags = ["-test.short"]
5 | Root = "$HOME/work/go/"
6 | # RunWrapper = ["foo"] # Optional command wrapper
7 | # Disabled = true # Don't run this configuration
8 |
9 | [[Configurations]]
10 | Name = "Test"
11 | # GcFlags = "-d=ssa/insert_resched_checks/off"
12 | # GCEnv = ["GOEXPERIMENT=something"]
13 | RunEnv = ["GOGC=100"]
14 | RunFlags = ["-test.short"]
15 | Root = "$HOME/work/go-dev/"
16 |
--------------------------------------------------------------------------------
/sweet/benchmarks/biogo-igor/README.md:
--------------------------------------------------------------------------------
1 | # biogo-igor Benchmark
2 |
3 | This directory contains a benchmark that takes pairwise alignment data as
4 | produced by PALS or krishna, and reports repeat feature family groupings in
5 | JSON format. Powered by the biogo bioinformatics library.
6 |
7 | The benchmark is a modified form of the Igor example which may be found in
8 | the [biogo examples repository](https://github.com/biogo/examples) and thus
9 | retains the [BSD-3-clause license](../../third_party/biogo-examples/LICENSE)
10 | associated.
11 |
--------------------------------------------------------------------------------
/sweet/common/generator.go:
--------------------------------------------------------------------------------
1 | // Copyright 2021 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package common
6 |
7 | type GenConfig struct {
8 | AssetsDir string
9 | SourceAssetsDir string
10 | OutputDir string
11 | GoTool *Go
12 | }
13 |
14 | type Generator interface {
15 | // Generate generates a new assets directory
16 | // from an old assets directory, given a configuration.
17 | Generate(*GenConfig) error
18 | }
19 |
--------------------------------------------------------------------------------
/cmd/bent/scripts/cpuprofile:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # Run args as command, but run cpuprofile and then pprof to capture test cpuprofile output
3 | if [ -n "${BENT_PGO}" ] ; then
4 | pf="${BENT_PGO}/${BENT_BENCH}.prof"
5 | mkdir -p ${BENT_PGO}
6 | else
7 | pf="${BENT_PROFILES}/${BENT_BINARY}_${BENT_I}.prof"
8 | mkdir -p ${BENT_PROFILES}
9 | fi
10 | "$@" -test.cpuprofile="$pf"
11 | echo cpuprofile in "$pf"
12 | if [[ x`which pprof` == x"" ]] ; then
13 | go tool pprof -text -flat -nodecount=20 "$pf"
14 | else
15 | pprof -text -flat -nodecount=20 "$pf"
16 | fi
17 |
--------------------------------------------------------------------------------
/driver/driver_go12.go:
--------------------------------------------------------------------------------
1 | // Copyright 2013 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | //go:build go1.2
6 |
7 | package driver
8 |
9 | import (
10 | "runtime"
11 | )
12 |
13 | // New mem stats added in Go1.2
14 | func collectGo12MemStats(res *Result, mstats0, mstats1 *runtime.MemStats) {
15 | res.Metrics["GC-bytes-from-system"] = mstats1.GCSys
16 | res.Metrics["other-bytes-from-system"] = mstats1.OtherSys + mstats1.MSpanSys + mstats1.MCacheSys + mstats1.BuckHashSys
17 | }
18 |
--------------------------------------------------------------------------------
/sweet/benchmarks/internal/driver/mem.go:
--------------------------------------------------------------------------------
1 | // Copyright 2021 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | //go:build !linux
6 |
7 | package driver
8 |
9 | import "os"
10 |
11 | func ReadRSS(pid int) (uint64, error) {
12 | return 0, nil
13 | }
14 |
15 | func ReadPeakRSS(pid int) (uint64, error) {
16 | return 0, nil
17 | }
18 |
19 | func ReadPeakVM(pid int) (uint64, error) {
20 | return 0, nil
21 | }
22 |
23 | func ProcessPeakRSS(s *os.ProcessState) uint64 {
24 | return 0
25 | }
26 |
--------------------------------------------------------------------------------
/cmd/bent/configs/configurations-gollvm.toml:
--------------------------------------------------------------------------------
1 | [[Configurations]]
2 | Name = "Go"
3 | Root = "$HOME/work/go/"
4 | RunWrapper = ["cpuprofile"]
5 |
6 | [[Configurations]]
7 | Name = "Go-noasm"
8 | BuildFlags = ["-tags=noasm"]
9 | Root = "$HOME/work/go/"
10 | RunWrapper = ["cpuprofile"]
11 |
12 | [[Configurations]]
13 | Name = "Gollvm"
14 | Root = "$HOME/work/gollvm/"
15 | BuildFlags = ["-gccgoflags=all=-O3 -static-libgo","-tags=noasm"]
16 | RunEnv = ["LD_LIBRARY_PATH=$HOME/work/gollvm/lib64"]
17 | GcEnv = ["LD_LIBRARY_PATH=$HOME/work/gollvm/lib64"]
18 | RunWrapper = ["cpuprofile"]
19 |
--------------------------------------------------------------------------------
/sweet/cli/assets/version.go:
--------------------------------------------------------------------------------
1 | // Copyright 2021 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package assets
6 |
7 | import (
8 | "fmt"
9 | "regexp"
10 | )
11 |
12 | var versionRegexp = regexp.MustCompile(`v\d+\.\d+\.\d+`)
13 |
14 | func ValidateVersion(version string) error {
15 | if !versionRegexp.MatchString(version) {
16 | return fmt.Errorf("version must be of the form 'v1.2.3'")
17 | }
18 | return nil
19 | }
20 |
21 | func ToCIPDVersion(version string) string {
22 | return version[1:]
23 | }
24 |
--------------------------------------------------------------------------------
/sweet/source-assets/gvisor/syscall/README.md:
--------------------------------------------------------------------------------
1 | # gVisor Syscall Benchmark
2 |
3 | This directory contains a linux/amd64 Go binary which measures raw
4 | syscall performance by running getppid (which is usually not cached
5 | in userspace) a fixed number of iterations. It would be ideal to run
6 | for a specified amount of time instead, but plumbing results back
7 | is a pain, and this is good enough. The benchmark source is in the
8 | `src` directory.
9 |
10 | The benchmark is loosely based off the syscall benchmark in [gVisor's
11 | repository](https://github.com/google/gvisor/tree/3ad6d30/benchmarks/workloads/syscall).
12 |
--------------------------------------------------------------------------------
/driver/driver_wasm.go:
--------------------------------------------------------------------------------
1 | // Copyright 2023 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | //go:build wasm
6 |
7 | package driver
8 |
9 | import (
10 | "fmt"
11 | "os/exec"
12 | "runtime"
13 | )
14 |
15 | type sysStats struct{}
16 |
17 | func InitSysStats(N uint64) sysStats { return sysStats{} }
18 |
19 | func (sysStats) Collect(*Result) {}
20 |
21 | func RunAndCollectSysStats(cmd *exec.Cmd, res *Result, N uint64, prefix string) (string, error) {
22 | return "", fmt.Errorf("not implemented on %s/%s", runtime.GOOS, runtime.GOARCH)
23 | }
24 |
--------------------------------------------------------------------------------
/cmd/bent/configs/configurations-cmpjob.toml:
--------------------------------------------------------------------------------
1 | [[Configurations]]
2 | Name = "Old"
3 | Root = "$ROOT/go-old"
4 | LdFlags = "-randlayout=0x${BENT_K}a${BENT_I}"
5 | AfterBuild = [ "benchsize", "benchdwarf" ]
6 |
7 | [[Configurations]]
8 | Name = "New"
9 | Root = "$ROOT/go-new"
10 | LdFlags = "-randlayout=0x${BENT_K}a${BENT_I}"
11 | AfterBuild = [ "benchsize", "benchdwarf" ]
12 |
13 | [[Configurations]]
14 | Name = "Old-phase"
15 | Root = "$ROOT/go-old"
16 | GcFlags = "all=-d=ssa/all/time=1"
17 | Disabled = true
18 |
19 | [[Configurations]]
20 | Name = "New-phase"
21 | Root = "$ROOT/go-new"
22 | GcFlags = "all=-d=ssa/all/time=1"
23 | Disabled = true
24 |
25 |
--------------------------------------------------------------------------------
/driver/driver_stub.go:
--------------------------------------------------------------------------------
1 | // Copyright 2013 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | //go:build aix || dragonfly || freebsd || netbsd || openbsd || solaris || wasm
6 |
7 | package driver
8 |
9 | const rssMultiplier = 1
10 |
11 | func RunUnderProfiler(args ...string) (string, string) {
12 | return "", ""
13 | }
14 |
15 | // Size runs size command on the file. Returns filename with output. Any errors are ignored.
16 | func Size(file string) string {
17 | return ""
18 | }
19 |
20 | func getVMPeak() uint64 {
21 | return 0
22 | }
23 |
24 | func setProcessAffinity(v int) {
25 | }
26 |
--------------------------------------------------------------------------------
/cmd/bent/configs/benchmarks-gc.toml:
--------------------------------------------------------------------------------
1 | # All (discovered as of 2018-04-02) benchmarks that do a lot of allocation, either in size or number
2 |
3 | [[Benchmarks]]
4 | Name = "ethereum_storage"
5 | Benchmarks = "Benchmark(Join|SplitTree)" # SplitPyramid seems to have a bug
6 | NotSandboxed = true # Won't cross-compile to Linux on MacOS
7 |
8 | [[Benchmarks]]
9 | Name = "ethereum_core"
10 | Benchmarks = "Benchmark(InsertChain_ring)" # ChainRead crashes as of 1.10 on 2018-03-16
11 | NotSandboxed = true # Won't cross-compile to Linux on MacOS
12 | Disabled = true
13 |
14 | [[Benchmarks]]
15 | Name = "minio"
16 | Tests = "none" # Don't run these tests; they hang, etc.
17 | Benchmarks = "BenchmarkGetObject.*Mb" # not Get|Put|List
18 | Disabled = true
19 |
--------------------------------------------------------------------------------
/sweet/common/platforms.go:
--------------------------------------------------------------------------------
1 | // Copyright 2021 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package common
6 |
7 | import (
8 | "fmt"
9 | "runtime"
10 | )
11 |
12 | type Platform struct {
13 | GOOS, GOARCH string
14 | }
15 |
16 | func (p Platform) String() string {
17 | return fmt.Sprintf("%s/%s", p.GOOS, p.GOARCH)
18 | }
19 |
20 | func (p Platform) BuildEnv(e *Env) *Env {
21 | return e.MustSet(
22 | fmt.Sprintf("GOOS=%s", p.GOOS),
23 | fmt.Sprintf("GOARCH=%s", p.GOARCH),
24 | )
25 | }
26 |
27 | var SupportedPlatforms = []Platform{
28 | {"linux", "amd64"},
29 | }
30 |
31 | func CurrentPlatform() Platform {
32 | return Platform{
33 | GOOS: runtime.GOOS,
34 | GOARCH: runtime.GOARCH,
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/third_party/biogo-examples/krishna/write.go:
--------------------------------------------------------------------------------
1 | // Copyright ©2014 The bíogo Authors. All rights reserved.
2 | // Copyright 2021 The Go Authors. All rights reserved.
3 | // Use of this source code is governed by a BSD-style
4 | // license that can be found in the LICENSE file.
5 |
6 | package krishna
7 |
8 | import (
9 | "sync"
10 |
11 | "github.com/biogo/biogo/align/pals"
12 | "github.com/biogo/biogo/align/pals/dp"
13 | )
14 |
15 | var wlock = &sync.Mutex{}
16 |
17 | func writeDPHits(w *pals.Writer, target, query *pals.Packed, hits []dp.Hit, comp bool) (n int, err error) {
18 | wlock.Lock()
19 | defer wlock.Unlock()
20 |
21 | for _, hit := range hits {
22 | pair, err := pals.NewPair(target, query, hit, comp)
23 | if err != nil {
24 | return n, err
25 | } else {
26 | ln, err := w.Write(pair)
27 | n += ln
28 | if err != nil {
29 | return n, err
30 | }
31 | }
32 | }
33 |
34 | return
35 | }
36 |
--------------------------------------------------------------------------------
/sweet/benchmarks/gvisor/startup.go:
--------------------------------------------------------------------------------
1 | // Copyright 2021 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | //go:build linux
6 |
7 | package main
8 |
9 | import (
10 | "io"
11 | "path/filepath"
12 |
13 | "golang.org/x/benchmarks/sweet/benchmarks/internal/driver"
14 | )
15 |
16 | type startup struct{}
17 |
18 | func (b startup) name() string {
19 | return "GVisorStartup"
20 | }
21 |
22 | func (b startup) run(cfg *config, out io.Writer) error {
23 | cmd, postExit := cfg.runscCmd("-rootless", "-network=none", "run", "bench")
24 | cmd.Stdout = out
25 | cmd.Stderr = out
26 | cmd.Dir = filepath.Join(cfg.assetsDir, "startup")
27 | defer func() {
28 | for _, fn := range postExit {
29 | fn()
30 | }
31 | }()
32 | return driver.RunBenchmark(b.name(), func(d *driver.B) error {
33 | return cmd.Run()
34 | }, driver.DoTime(true))
35 | }
36 |
--------------------------------------------------------------------------------
/sweet/benchmarks/internal/par/funcs.go:
--------------------------------------------------------------------------------
1 | // Copyright 2024 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package par
6 |
7 | import (
8 | "reflect"
9 | "sync"
10 | )
11 |
12 | type Funcs struct {
13 | funcs []func()
14 | }
15 |
16 | func (f *Funcs) Add(fn any) {
17 | if fn, ok := fn.(func()); ok {
18 | // Easy
19 | f.funcs = append(f.funcs, fn)
20 | return
21 | }
22 |
23 | rv := reflect.ValueOf(fn)
24 | if rv.Kind() != reflect.Func || rv.Type().NumIn() != 0 {
25 | panic("fn must be a function with zero arguments")
26 | }
27 | f.funcs = append(f.funcs, func() { rv.Call(nil) })
28 | }
29 |
30 | func (f *Funcs) Run() {
31 | var wg sync.WaitGroup
32 | for _, fn := range f.funcs {
33 | wg.Add(1)
34 | go func(fn func()) {
35 | defer wg.Done()
36 | fn()
37 | }(fn)
38 | }
39 | f.funcs = nil
40 | wg.Wait()
41 | }
42 |
--------------------------------------------------------------------------------
/driver/driver_go15.go:
--------------------------------------------------------------------------------
1 | // Copyright 2015 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | //go:build go1.5
6 |
7 | package driver
8 |
9 | import (
10 | "flag"
11 | "fmt"
12 | "os"
13 | "runtime/trace"
14 | )
15 |
16 | var traceFile = flag.String("trace", "", "write an execution trace to the named file after execution")
17 |
18 | func startTraceGo15() func() {
19 | // New runtime tracing added in Go 1.5.
20 | if *traceFile != "" {
21 | f, err := os.Create(*traceFile)
22 | if err != nil {
23 | fmt.Fprintln(os.Stderr, err)
24 | os.Exit(1)
25 | }
26 | if err := trace.Start(f); err != nil {
27 | fmt.Fprintf(os.Stderr, "can't start tracing: %s\n", err)
28 | os.Exit(1)
29 | }
30 |
31 | return func() {
32 | trace.Stop()
33 | f.Close()
34 | }
35 | }
36 | return func() {}
37 | }
38 |
39 | func init() {
40 | startTrace = startTraceGo15
41 | }
42 |
--------------------------------------------------------------------------------
/sweet/benchmarks/tile38/README.md:
--------------------------------------------------------------------------------
1 | # Tile38 Benchmark
2 |
3 | The benchmark consists of stress-testing the [Tile38](https://tile38.com) server
4 | with three different kinds of commands:
5 | * `WITHIN` -- Each request looks for points or regions in the database which
6 | lie wholly within 100km of a given input point.
7 | * `INTERSECTS` -- Same as `WITHIN`, but bounds may simply overlap with the
8 | search space, rather than be wholly enclosed by it.
9 | * `NEARBY` -- Each request looks for the 100-nearest-neighbors to a given input
10 | point.
11 |
12 | Each command is run for the amount of time specified in the CLI (default 20
13 | seconds).
14 |
15 | Much of the idea for the benchmarks is derived from the `tile38-benchmark`
16 | program built as part of building tile38 from the [upstream
17 | repository](https://github.com/tidwall/tile38/tree/master/cmd/tile38-benchmark).
18 |
19 | This implementation is custom and not derived via source modification from the
20 | `tile38-benchmark` tool.
21 |
--------------------------------------------------------------------------------
/sweet/cli/assets/cache.go:
--------------------------------------------------------------------------------
1 | // Copyright 2021 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package assets
6 |
7 | import (
8 | "errors"
9 | "fmt"
10 | "os"
11 | "path/filepath"
12 | )
13 |
14 | var ErrNotInCache = errors.New("not found in cache")
15 |
16 | func CachedAssets(cache, version string) (string, error) {
17 | name := version
18 | if err := os.MkdirAll(cache, os.ModePerm); err != nil {
19 | return "", fmt.Errorf("failed to create cache directory: %w", err)
20 | }
21 | cacheloc := filepath.Join(cache, name)
22 | if _, err := os.Lstat(cacheloc); os.IsNotExist(err) {
23 | return cacheloc, ErrNotInCache
24 | } else if err != nil {
25 | return "", fmt.Errorf("failed to check cache: %w", err)
26 | }
27 | return cacheloc, nil
28 | }
29 |
30 | func CacheDefault() string {
31 | cache, err := os.UserCacheDir()
32 | if err == nil {
33 | cache = filepath.Join(cache, "go-sweet")
34 | }
35 | return cache
36 | }
37 |
38 | const CIPDCacheDir = ".cipd-cache"
39 |
--------------------------------------------------------------------------------
/gc_latency/main.go:
--------------------------------------------------------------------------------
1 | // Copyright 2023 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package main
6 |
7 | // Gc_latency is a modified version of a program that tickled multiple
8 | // latency glitches in the Go GC/runtime. This version reports the time
9 | // of the worst observed glitches so that they can be easily located in
10 | // a trace file and debugged. This program can also be run as a benchmark
11 | // to allow easier automated performance monitoring; the benchmark doesn't
12 | // report worst case times because those are too noisy.
13 | //
14 | // Usage:
15 | //
16 | // gc_latency [flags]
17 | //
18 | // Flags (as main):
19 | // -fluff
20 | // insert 'fluff' into allocation runs to break up sweeps
21 | // -how string
22 | // how the buffer is allocated = {stack,heap,global} (default "stack")
23 | // -trace string
24 | // name of trace file to create
25 | func main() {
26 | howAllocated, doFluffFlag := flags()
27 | lb := &LB{howAllocated: howAllocated, doFluff: doFluffFlag}
28 | lb.bench(nil)
29 | }
30 |
--------------------------------------------------------------------------------
/cmd/bent/scripts/tweet-results:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | RUN=$1
4 | shopt -s extglob
5 |
6 | BS=`which benchseries`
7 | BT=`which bench-tweet`
8 |
9 | doit=yes
10 |
11 | if [ "x$BS" = "x" ] ; then
12 | echo "Need benchseries (currently in a CL): https://go-review.googlesource.com/c/perf/+/218923 "
13 | doit=no
14 | fi
15 |
16 | if [ "x$BT" = "x" ] ; then
17 | echo "Need bench-tweet: go get github.com/dr2chase/go-bench-tweet-bot/cmd/bench-tweet"
18 | doit=no
19 | fi
20 |
21 | if [ ! -f .twitter/drchase-benchmark-bot ] ; then
22 | echo "No twitter credentials found, looking for .twitter/drchase-benchmark-bot"
23 | doit=no
24 | fi
25 |
26 | if [ $doit = no ] ; then
27 | echo Cannot tweet about the benchmarks
28 | exit 1
29 | fi
30 |
31 | URL="https://perf.golang.org/search?q=bentstamp%3A${RUN}"
32 | echo ${URL} > ${RUN}.tmp
33 | (cd bench ; benchseries -sparse -png ../png -series bentstamp -last ns-per-op,build-user-ns-per-op Go*-opt.* !(Go)*-opt.*) >> ${RUN}.tmp
34 |
35 | wc ${RUN}.tmp
36 | bench-tweet -i ${RUN}.tmp -m png/ns-per-op.png -m png/build-user-ns-per-op.png -m png/text-bytes.png -m png/total-bytes.png
37 | rm ${RUN}.tmp
38 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing to Go
2 |
3 | Go is an open source project.
4 |
5 | It is the work of hundreds of contributors. We appreciate your help!
6 |
7 |
8 | ## Filing issues
9 |
10 | When [filing an issue](https://golang.org/issue/new), make sure to answer these five questions:
11 |
12 | 1. What version of Go are you using (`go version`)?
13 | 2. What operating system and processor architecture are you using?
14 | 3. What did you do?
15 | 4. What did you expect to see?
16 | 5. What did you see instead?
17 |
18 | General questions should go to the [golang-nuts mailing list](https://groups.google.com/group/golang-nuts) instead of the issue tracker.
19 | The gophers there will answer or ask you to file an issue if you've tripped over a bug.
20 |
21 | ## Contributing code
22 |
23 | Please read the [Contribution Guidelines](https://golang.org/doc/contribute.html)
24 | before sending patches.
25 |
26 | **We do not accept GitHub pull requests**
27 | (we use [Gerrit](https://code.google.com/p/gerrit/) instead for code review).
28 |
29 | Unless otherwise noted, the Go source files are distributed under
30 | the BSD-style license found in the LICENSE file.
31 |
32 |
--------------------------------------------------------------------------------
/cmd/bent/configs/benchmarks-gcplus.toml:
--------------------------------------------------------------------------------
1 | # All (discovered as of 2018-04-02) benchmarks that do a lot of allocation, either in size or number
2 |
3 | [[Benchmarks]]
4 | Name = "ethereum_storage"
5 | Benchmarks = "Benchmark(Join|SplitTree)_[678]" # SplitPyramid seems to have a bug
6 | NotSandboxed = true # Won't cross-compile to Linux on MacOS
7 |
8 | [[Benchmarks]]
9 | Name = "ethereum_core"
10 | Benchmarks = "Benchmark(InsertChain_ring|PoolBatchInsert10000|ChainWrite)" # ChainRead crashes as of 1.10 on 2018-03-16
11 | NotSandboxed = true # Won't cross-compile to Linux on MacOS
12 | Disabled = true
13 |
14 | [[Benchmarks]]
15 | Name = "minio"
16 | Tests = "none" # Don't run these tests; they hang, etc.
17 | Benchmarks = "BenchmarkGetObject.*Mb" # not Get|Put|List
18 | Disabled = true
19 |
20 | [[Benchmarks]]
21 | Name = "spexs2"
22 | Benchmarks = "BenchmarkRun"
23 |
24 | [[Benchmarks]]
25 | Name = "ethereum_ethash"
26 | Benchmarks = "BenchmarkCacheGeneration"
27 | NotSandboxed = true # Won't cross-compile to Linux on MacOS
28 |
29 | [[Benchmarks]]
30 | Name = "gonum_path"
31 | Benchmarks = "BenchmarkRandomGraphDominators/gnm-n=1e[567]"
32 |
--------------------------------------------------------------------------------
/sweet/benchmarks/gvisor/syscall.go:
--------------------------------------------------------------------------------
1 | // Copyright 2021 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | //go:build linux
6 |
7 | package main
8 |
9 | import (
10 | "io"
11 |
12 | "golang.org/x/benchmarks/sweet/benchmarks/internal/cgroups"
13 | "golang.org/x/benchmarks/sweet/benchmarks/internal/driver"
14 | )
15 |
16 | type systemCall struct {
17 | ops int
18 | }
19 |
20 | func (b systemCall) name() string {
21 | return "GVisorSyscall"
22 | }
23 |
24 | func (b systemCall) run(cfg *config, out io.Writer) error {
25 | baseCmd, postExit := cfg.runscCmd("-rootless", "do", workloadsPath(cfg.assetsDir, "syscall"))
26 | baseCmd.Stdout = out
27 | baseCmd.Stderr = out
28 | cmd, err := cgroups.WrapCommand(baseCmd, "test-syscall.scope")
29 | if err != nil {
30 | return err
31 | }
32 | defer func() {
33 | for _, fn := range postExit {
34 | fn()
35 | }
36 | }()
37 | return driver.RunBenchmark(b.name(), func(d *driver.B) error {
38 | d.Ops(b.ops)
39 | d.ResetTimer()
40 | return cmd.Run()
41 | }, driver.DoTime(true), driver.DoAvgRSS(cmd.RSSFunc()))
42 | }
43 |
--------------------------------------------------------------------------------
/cmd/bent/patches/ethereum_core:
--------------------------------------------------------------------------------
1 | cd gopath/src/github.com/ethereum/go-ethereum
2 | patch -p1 <<"EOF"
3 | diff --git a/core/blockchain.go b/core/blockchain.go
4 | index 63f60ca28..4e57caab2 100644
5 | --- a/core/blockchain.go
6 | +++ b/core/blockchain.go
7 | @@ -339,13 +339,21 @@ func (bc *BlockChain) GasLimit() uint64 {
8 | // CurrentBlock retrieves the current head block of the canonical chain. The
9 | // block is retrieved from the blockchain's internal cache.
10 | func (bc *BlockChain) CurrentBlock() *types.Block {
11 | - return bc.currentBlock.Load().(*types.Block)
12 | + x := bc.currentBlock.Load()
13 | + if x == nil {
14 | + return nil
15 | + }
16 | + return x.(*types.Block)
17 | }
18 |
19 | // CurrentFastBlock retrieves the current fast-sync head block of the canonical
20 | // chain. The block is retrieved from the blockchain's internal cache.
21 | func (bc *BlockChain) CurrentFastBlock() *types.Block {
22 | - return bc.currentFastBlock.Load().(*types.Block)
23 | + x := bc.currentFastBlock.Load()
24 | + if x == nil {
25 | + return nil
26 | + }
27 | + return x.(*types.Block)
28 | }
29 |
30 | // SetProcessor sets the processor required for making state modifications.
31 | EOF
32 |
--------------------------------------------------------------------------------
/driver/driver_darwin.go:
--------------------------------------------------------------------------------
1 | // Copyright 2013 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | //go:build !linux
6 |
7 | package driver
8 |
9 | import (
10 | "bytes"
11 | "log"
12 | "os"
13 | "os/exec"
14 | )
15 |
16 | const rssMultiplier = 1
17 |
18 | func RunUnderProfiler(args ...string) (string, string) {
19 | return "", ""
20 | }
21 |
22 | // Size runs size command on the file. Returns filename with output. Any errors are ignored.
23 | func Size(file string) string {
24 | resf, err := os.Create(tempFilename("size.txt"))
25 | if err != nil {
26 | log.Printf("Failed to create output file: %v", err)
27 | return ""
28 | }
29 | defer resf.Close()
30 |
31 | var stderr bytes.Buffer
32 | cmd := exec.Command("size", "-m", file)
33 | cmd.Stdout = resf
34 | cmd.Stderr = &stderr
35 | if err := cmd.Run(); err != nil {
36 | log.Printf("Failed to execute 'size -m %v': %v\n%v", file, err, stderr.String())
37 | return ""
38 | }
39 |
40 | return resf.Name()
41 | }
42 |
43 | func getVMPeak() uint64 {
44 | return 0
45 | }
46 |
47 | func setProcessAffinity(v int) {
48 | }
49 |
--------------------------------------------------------------------------------
/cmd/bent/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # How to Contribute
2 |
3 | We'd love to accept your patches and contributions to this project. There are
4 | just a few small guidelines you need to follow.
5 |
6 | ## Contributor License Agreement
7 |
8 | Contributions to this project must be accompanied by a Contributor License
9 | Agreement. You (or your employer) retain the copyright to your contribution;
10 | this simply gives us permission to use and redistribute your contributions as
11 | part of the project. Head over to to see
12 | your current agreements on file or to sign a new one.
13 |
14 | You generally only need to submit a CLA once, so if you've already submitted one
15 | (even if it was for a different project), you probably don't need to do it
16 | again.
17 |
18 | ## Code reviews
19 |
20 | All submissions, including submissions by project members, require review. We
21 | use GitHub pull requests for this purpose. Consult
22 | [GitHub Help](https://help.github.com/articles/about-pull-requests/) for more
23 | information on using pull requests.
24 |
25 | ## Community Guidelines
26 |
27 | This project follows [Google's Open Source Community Guidelines](https://opensource.google.com/conduct/).
28 |
--------------------------------------------------------------------------------
/third_party/biogo-examples/krishna/packseqs.go:
--------------------------------------------------------------------------------
1 | // Copyright ©2014 The bíogo Authors. All rights reserved.
2 | // Copyright 2021 The Go Authors. All rights reserved.
3 | // Use of this source code is governed by a BSD-style
4 | // license that can be found in the LICENSE file.
5 |
6 | package krishna
7 |
8 | import (
9 | "os"
10 | "path/filepath"
11 |
12 | "github.com/biogo/biogo/align/pals"
13 | "github.com/biogo/biogo/alphabet"
14 | "github.com/biogo/biogo/io/seqio/fasta"
15 | "github.com/biogo/biogo/seq"
16 | "github.com/biogo/biogo/seq/linear"
17 | )
18 |
19 | func packSequence(fileName string) (*pals.Packed, error) {
20 | _, name := filepath.Split(fileName)
21 | packer := pals.NewPacker(name)
22 |
23 | file, err := os.Open(fileName)
24 | if err != nil {
25 | return nil, err
26 | }
27 | defer file.Close()
28 | template := &linear.Seq{Annotation: seq.Annotation{Alpha: alphabet.DNA}}
29 | seqFile := fasta.NewReader(file, template)
30 |
31 | var seq seq.Sequence
32 | for {
33 | seq, err = seqFile.Read()
34 | if err != nil {
35 | break
36 | }
37 | _, err = packer.Pack(seq.(*linear.Seq))
38 | if err != nil {
39 | return nil, err
40 | }
41 | }
42 | return packer.FinalisePack(), nil
43 | }
44 |
--------------------------------------------------------------------------------
/sweet/benchmarks/internal/driver/mem_linux.go:
--------------------------------------------------------------------------------
1 | // Copyright 2021 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package driver
6 |
7 | import (
8 | "fmt"
9 | "os"
10 | "regexp"
11 | "strconv"
12 | "syscall"
13 | )
14 |
15 | var (
16 | reVmPeak = regexp.MustCompile(`VmPeak:\s*(\d+) kB`)
17 | reVmRSS = regexp.MustCompile(`VmRSS:\s*(\d+) kB`)
18 | reVmHWM = regexp.MustCompile(`VmHWM:\s*(\d+) kB`)
19 | )
20 |
21 | func readStat(pid int, r *regexp.Regexp) (uint64, error) {
22 | b, err := os.ReadFile(fmt.Sprintf("/proc/%d/status", pid))
23 | if err != nil {
24 | return 0, err
25 | }
26 | m := r.FindSubmatch(b)
27 | if len(m) < 2 {
28 | return 0, nil
29 | }
30 | val, err := strconv.ParseUint(string(m[1]), 10, 64)
31 | return val * 1024, err
32 | }
33 |
34 | func ReadRSS(pid int) (uint64, error) {
35 | return readStat(pid, reVmRSS)
36 | }
37 |
38 | func ReadPeakRSS(pid int) (uint64, error) {
39 | return readStat(pid, reVmHWM)
40 | }
41 |
42 | func ReadPeakVM(pid int) (uint64, error) {
43 | return readStat(pid, reVmPeak)
44 | }
45 |
46 | func ProcessPeakRSS(s *os.ProcessState) uint64 {
47 | return uint64(s.SysUsage().(*syscall.Rusage).Maxrss) * 1024
48 | }
49 |
--------------------------------------------------------------------------------
/sweet/cmd/sweet/get.go:
--------------------------------------------------------------------------------
1 | // Copyright 2021 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package main
6 |
7 | import (
8 | "flag"
9 | "fmt"
10 | "io"
11 |
12 | "golang.org/x/benchmarks/sweet/cli/assets"
13 | "golang.org/x/benchmarks/sweet/common"
14 | )
15 |
16 | const (
17 | getUsage = `Retrieves assets for benchmarks from GCS.
18 |
19 | Usage: %s get [flags]
20 | `
21 | )
22 |
23 | type getCmd struct {
24 | cache string
25 | copyDir string
26 | version string
27 | clean bool
28 | }
29 |
30 | func (*getCmd) Name() string { return "get" }
31 | func (*getCmd) Synopsis() string { return "Retrieves assets for benchmarks." }
32 | func (*getCmd) PrintUsage(w io.Writer, base string) {
33 | fmt.Fprintf(w, getUsage, base)
34 | }
35 |
36 | func (c *getCmd) SetFlags(f *flag.FlagSet) {
37 | f.StringVar(&c.cache, "cache", assets.CacheDefault(), "cache location for assets")
38 | f.StringVar(&c.version, "version", common.Version, "the version to download assets for")
39 | f.StringVar(&c.copyDir, "copy", "", "location to extract assets into, useful for development")
40 | f.BoolVar(&c.clean, "clean", false, "delete all cached assets before installing new ones")
41 | }
42 |
--------------------------------------------------------------------------------
/sweet/cmd/sweet/benchmark_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2024 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package main
6 |
7 | import (
8 | "fmt"
9 | "os"
10 | "strings"
11 | "testing"
12 | )
13 |
14 | func TestReadFileTail(t *testing.T) {
15 | tmpDir := t.TempDir()
16 | check := func(data string, want string) {
17 | t.Helper()
18 | f, err := os.CreateTemp(tmpDir, "")
19 | if err != nil {
20 | t.Fatalf("creating temp input file: %s", err)
21 | }
22 | defer f.Close()
23 | _, err = f.WriteString(data)
24 | if err != nil {
25 | t.Fatalf("writing temp input file: %s", err)
26 | }
27 |
28 | got, err := readFileTail(f)
29 |
30 | if got != want {
31 | t.Errorf("got:\n%q\nwant:\n%q", got, want)
32 | }
33 | }
34 |
35 | numbers := func(n, m int) string {
36 | var buf strings.Builder
37 | for i := n; i < m; i++ {
38 | fmt.Fprintf(&buf, "%d\n", i)
39 | }
40 | return buf.String()
41 | }
42 |
43 | // Basic test
44 | check(numbers(0, 40), numbers(20, 40))
45 | // Multiple blocks
46 | check(numbers(0, 5000), numbers(5000-20, 5000))
47 | // Byte limit
48 | check(
49 | strings.Repeat("a", 32<<10)+"\nb\n",
50 | strings.Repeat("a", 16<<10-3)+"\nb\n")
51 | }
52 |
--------------------------------------------------------------------------------
/cmd/bent/configs/configurations-random.toml:
--------------------------------------------------------------------------------
1 | # A sample configuration for benchmarking binaries whose function ordering has been randomized.
2 | # This is intended for use with the "-R n" flag and also requires Go > 1.22.
3 | # This is no longer necessary to use randomized linking because bent will automatically
4 | # insert LdFlags for randomized linking if nothing is supplied in the configuration, unless
5 | # a configuration needs to set additional LdFlags.
6 | #
7 | # BENT_K can be provided externally, for example in a shell script doing iterated benchmarking
8 | # or two create a different set of randomized link orders.
9 | #
10 | # Randomized function ordering creates differences in branch/target alignment which can then be
11 | # averaged to remove that artifact from benchmarking results, as recommended by
12 | # Charlie Curtsinger https://dl.acm.org/doi/10.1145/2451116.2451141
13 | #
14 | # Benchsize should report slightly different binary sizes if they are correctly linked.
15 | #
16 | [[Configurations]]
17 | Name = "Control-rand"
18 | LdFlags = "-randlayout=0x${BENT_K}a${BENT_I}"
19 | Root = "$HOME/work/go/"
20 | AfterBuild = [ "benchsize" ]
21 |
22 | [[Configurations]]
23 | Name = "Test-rand"
24 | LdFlags = "-randlayout=0x${BENT_K}a${BENT_I}"
25 | Root = "$HOME/work/go-dev/"
26 | AfterBuild = [ "benchsize" ]
27 |
--------------------------------------------------------------------------------
/PATENTS:
--------------------------------------------------------------------------------
1 | Additional IP Rights Grant (Patents)
2 |
3 | "This implementation" means the copyrightable works distributed by
4 | Google as part of the Go project.
5 |
6 | Google hereby grants to You a perpetual, worldwide, non-exclusive,
7 | no-charge, royalty-free, irrevocable (except as stated in this section)
8 | patent license to make, have made, use, offer to sell, sell, import,
9 | transfer and otherwise run, modify and propagate the contents of this
10 | implementation of Go, where such license applies only to those patent
11 | claims, both currently owned or controlled by Google and acquired in
12 | the future, licensable by Google that are necessarily infringed by this
13 | implementation of Go. This grant does not include claims that would be
14 | infringed only as a consequence of further modification of this
15 | implementation. If you or your agent or exclusive licensee institute or
16 | order or agree to the institution of patent litigation against any
17 | entity (including a cross-claim or counterclaim in a lawsuit) alleging
18 | that this implementation of Go or any code incorporated within this
19 | implementation of Go constitutes direct or contributory patent
20 | infringement, or inducement of patent infringement, then any patent
21 | rights granted to you under this License for this implementation of Go
22 | shall terminate as of the date such litigation is filed.
23 |
--------------------------------------------------------------------------------
/stats/itree_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2021 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package stats
6 |
7 | import (
8 | "reflect"
9 | "testing"
10 | )
11 |
12 | func TestIntervalTree(t *testing.T) {
13 | t.Parallel()
14 | inserts := []struct {
15 | v float64
16 | tree []int
17 | median float64
18 | }{
19 | // These values were pulled from the appendix of the edm paper where the
20 | // interval tree is described.
21 | {0.09, []int{1, 1, 0, 1, 0, 0, 0}, 0.25},
22 | {0.42, []int{2, 2, 0, 1, 1, 0, 0}, 0.125},
23 | {0.99, []int{3, 2, 1, 1, 1, 0, 1}, 0.25},
24 | {0.36, []int{4, 3, 1, 1, 2, 0, 1}, 0.375},
25 | }
26 | tree := NewIntervalTree(2)
27 | if l := tree.NumElements(); l != 0 {
28 | t.Errorf("tree.Length() = %d, expected 0", l)
29 | }
30 | if v := tree.Median(); v != 0 {
31 | t.Errorf("tree.Median() = %f, expected 0", v)
32 | }
33 | for i, ins := range inserts {
34 | tree.Insert(ins.v)
35 | if !reflect.DeepEqual(tree.vals, ins.tree) {
36 | t.Errorf("[%d] tree.Insert(%v) = %v, expected %v", i, ins.v, tree.vals, ins.tree)
37 | }
38 | if l := tree.NumElements(); l != i+1 {
39 | t.Errorf("[%d] tree.Length() = %d, expected %d", i, l, i+1)
40 | }
41 | if v := tree.Median(); v != ins.median {
42 | t.Errorf("[%d] tree.Median() = %f, expected %f", i, v, ins.median)
43 | }
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/third_party/biogo-examples/igor/igor/write.go:
--------------------------------------------------------------------------------
1 | // Copyright ©2014 The bíogo Authors. All rights reserved.
2 | // Copyright 2021 The Go Authors. All rights reserved.
3 | // Use of this source code is governed by a BSD-style
4 | // license that can be found in the LICENSE file.
5 |
6 | package igor
7 |
8 | import (
9 | "encoding/json"
10 | "io"
11 |
12 | "github.com/biogo/biogo/align/pals"
13 | "github.com/biogo/biogo/seq"
14 | "github.com/biogo/graph"
15 | )
16 |
17 | func WriteJSON(cc []graph.Nodes, w io.Writer) error {
18 | type feat struct {
19 | C string
20 | S int
21 | E int
22 | O seq.Strand
23 | }
24 | var (
25 | a feat
26 | f []feat
27 | j = json.NewEncoder(w)
28 | )
29 |
30 | seen := make(map[feat]struct{})
31 | var fi int
32 | for _, fam := range cc {
33 | for _, p := range fam {
34 | pile := p.(*pals.Pile)
35 |
36 | a.C = pile.Location().Name()
37 | a.S = pile.Start()
38 | a.E = pile.End()
39 | a.O = pile.Strand
40 | if _, ok := seen[a]; !ok && pile.Loc != nil {
41 | seen[a] = struct{}{}
42 | f = append(f, a)
43 | }
44 | }
45 | switch len(f) {
46 | case 0, 1:
47 | continue
48 | default:
49 | for i := 0; i < len(f); {
50 | if f[i].O == seq.None {
51 | f[i], f = f[len(f)-1], f[:len(f)-1]
52 | } else {
53 | i++
54 | }
55 | }
56 | }
57 | if len(f) < 2 {
58 | continue
59 | }
60 | err := j.Encode(f)
61 | if err != nil {
62 | return err
63 | }
64 | f = f[:0]
65 | fi++
66 | }
67 | return nil
68 | }
69 |
--------------------------------------------------------------------------------
/cmd/bent/patches/ericlagergren_decimal:
--------------------------------------------------------------------------------
1 | cd gopath/src/github.com/ericlagergren/decimal
2 | patch -p1 <<"EOF"
3 | diff --git a/benchmarks/pi_test.go b/benchmarks/pi_test.go
4 | index 86d1a15..b1310ee 100644
5 | --- a/benchmarks/pi_test.go
6 | +++ b/benchmarks/pi_test.go
7 | @@ -67,8 +67,8 @@ var (
8 | thirtyTwo = decimal.New(32, 0)
9 | apdEight = apd.New(8, 0)
10 | apdThirtyTwo = apd.New(32, 0)
11 | - dnumEight = dnum.NewDnum(false, 8, 0)
12 | - dnumThirtyTwo = dnum.NewDnum(false, 32, 0)
13 | + dnumEight = dnum.FromInt(8)
14 | + dnumThirtyTwo = dnum.FromInt(32)
15 | ssdecEight = ssdec.New(8, 0)
16 | ssdecThirtyTwo = ssdec.New(32, 0)
17 | infEight = inf.NewDec(8, 0)
18 | @@ -131,16 +131,16 @@ func calcPi_shopSpring(prec int32) ssdec.Decimal {
19 |
20 | func calcPi_dnum() dnum.Dnum {
21 | var (
22 | - lasts = dnum.NewDnum(false, 0, 0)
23 | - t = dnum.NewDnum(false, 3, 0)
24 | - s = dnum.NewDnum(false, 3, 0)
25 | - n = dnum.NewDnum(false, 1, 0)
26 | - na = dnum.NewDnum(false, 0, 0)
27 | - d = dnum.NewDnum(false, 0, 0)
28 | - da = dnum.NewDnum(false, 24, 0)
29 | + lasts = dnum.FromInt(0)
30 | + t = dnum.FromInt(3)
31 | + s = dnum.FromInt(3)
32 | + n = dnum.FromInt(1)
33 | + na = dnum.FromInt(0)
34 | + d = dnum.FromInt(0)
35 | + da = dnum.FromInt(24)
36 | )
37 |
38 | - for dnum.Cmp(s, lasts) != 0 {
39 | + for dnum.Compare(s, lasts) != 0 {
40 | lasts = s
41 | n = dnum.Add(n, na)
42 | na = dnum.Add(na, dnumEight)
43 | EOF
44 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright 2009 The Go Authors.
2 |
3 | Redistribution and use in source and binary forms, with or without
4 | modification, are permitted provided that the following conditions are
5 | met:
6 |
7 | * Redistributions of source code must retain the above copyright
8 | notice, this list of conditions and the following disclaimer.
9 | * Redistributions in binary form must reproduce the above
10 | copyright notice, this list of conditions and the following disclaimer
11 | in the documentation and/or other materials provided with the
12 | distribution.
13 | * Neither the name of Google LLC nor the names of its
14 | contributors may be used to endorse or promote products derived from
15 | this software without specific prior written permission.
16 |
17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 |
--------------------------------------------------------------------------------
/gc_latency/latency_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2023 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package main
6 |
7 | import (
8 | "flag"
9 | "fmt"
10 | "os"
11 | "testing"
12 | )
13 |
14 | // Run as a test, reports allocation time statistics for stack, heap, and globally
15 | // allocated buffers, out to the 99.9999th percentile. Optionally reports worst
16 | // allocation time if -worst is specified, but this is normally too noisy for any
17 | // sort of trend tracking or alerting. The default test usually runs long enough that
18 | // it requires only one iteration.
19 |
20 | func TestMain(m *testing.M) {
21 | flag.BoolVar(&reportWorstFlag, "worst", false, "report otherwise too-noisy 'worst' metric in benchmark")
22 | flag.Parse()
23 | os.Exit(m.Run())
24 | }
25 |
26 | type testCase struct {
27 | howAlloc string
28 | withFluff bool
29 | }
30 |
31 | func BenchmarkGCLatency(b *testing.B) {
32 | tcs := []testCase{
33 | {"stack", false},
34 | {"stack", true},
35 | {"heap", false},
36 | {"heap", true},
37 | {"global", false},
38 | {"global", true},
39 | }
40 |
41 | if testing.Short() {
42 | tcs = []testCase{
43 | {"stack", false},
44 | {"heap", false},
45 | {"global", false},
46 | }
47 | }
48 |
49 | for _, tc := range tcs {
50 | lb := &LB{doFluff: tc.withFluff, howAllocated: tc.howAlloc}
51 | b.Run(fmt.Sprintf("how=%s/fluff=%v", tc.howAlloc, tc.withFluff),
52 | func(b *testing.B) { lb.bench(b) })
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/cmd/bent/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2019 The Go Authors. All rights reserved.
2 |
3 | Redistribution and use in source and binary forms, with or without
4 | modification, are permitted provided that the following conditions are
5 | met:
6 |
7 | * Redistributions of source code must retain the above copyright
8 | notice, this list of conditions and the following disclaimer.
9 | * Redistributions in binary form must reproduce the above
10 | copyright notice, this list of conditions and the following disclaimer
11 | in the documentation and/or other materials provided with the
12 | distribution.
13 | * Neither the name of Google Inc. nor the names of its
14 | contributors may be used to endorse or promote products derived from
15 | this software without specific prior written permission.
16 |
17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 |
--------------------------------------------------------------------------------
/cmd/bench/idle_linux.go:
--------------------------------------------------------------------------------
1 | // Copyright 2021 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package main
6 |
7 | import (
8 | "fmt"
9 | "log"
10 | "os"
11 | "strconv"
12 | "strings"
13 | "time"
14 | )
15 |
16 | const idleMaxLoad = 0.2
17 |
18 | // loadAvg returns the 1-minute load average.
19 | func loadAvg() (float64, error) {
20 | b, err := os.ReadFile("/proc/loadavg")
21 | if err != nil {
22 | return 0, fmt.Errorf("error reading /proc/loadavg: %w", err)
23 | }
24 |
25 | s := strings.TrimSpace(string(b))
26 | log.Printf("Load average: %s", s)
27 |
28 | parts := strings.Split(s, " ")
29 |
30 | avg, err := strconv.ParseFloat(parts[0], 64)
31 | if err != nil {
32 | return 0, fmt.Errorf("malformed load average %q: %v", parts[0], err)
33 | }
34 | return avg, nil
35 | }
36 |
37 | func waitForIdle() error {
38 | avg, err := loadAvg()
39 | if err != nil {
40 | return fmt.Errorf("error reading load average: %w", err)
41 | }
42 | if avg < idleMaxLoad {
43 | return nil
44 | }
45 |
46 | log.Printf("Waiting for load average to drop below %.2f...", idleMaxLoad)
47 |
48 | tick := time.NewTicker(30 * time.Second)
49 | defer tick.Stop()
50 |
51 | for _ = range tick.C {
52 | avg, err := loadAvg()
53 | if err != nil {
54 | return fmt.Errorf("error reading load average: %w", err)
55 | }
56 | if avg < idleMaxLoad {
57 | break
58 | }
59 |
60 | log.Printf("Waiting for load average to drop below %.2f...", idleMaxLoad)
61 | }
62 |
63 | return nil
64 | }
65 |
--------------------------------------------------------------------------------
/README:
--------------------------------------------------------------------------------
1 | This subrepository holds macro-benchmarks used for Go performance
2 | development and monitoring.
3 |
4 | Each benchmark is compiled into a separate binary. To build and
5 | install them all in the current directory, execute:
6 |
7 | $ GOBIN=$PWD go get golang.org/x/benchmarks/...
8 |
9 | To run a benchmark, simply execute its binary.
10 |
11 | Each binary has a number of flags to control benchmark duration, etc.
12 | Run with '-help' to get the full list of flags.
13 |
14 | When the benchmarking finishes, the binary prints results in the
15 | standard Go benchmark format [1]:
16 |
17 | $ garbage
18 | BenchmarkGarbage/benchmem-MB=64-4 2000 6443223 ns/op 6008832 GC-bytes-from-system 230521 STW-ns/GC 15329 STW-ns/op 2780501 allocated-bytes/op 68636 allocs/op 119041368 bytes-from-system 104202240 heap-bytes-from-system 8109400 other-bytes-from-system 112427008 peak-RSS-bytes 121511936 peak-VM-bytes 720896 stack-bytes-from-system 25194000 user+sys-ns/op
19 |
20 | This format can be processed by tools like benchstat
21 | (https://golang.org/x/perf/cmd/benchstat) and benchplot
22 | (https://godoc.org/github.com/aclements/go-misc/benchplot).
23 |
24 | Required extra tools:
25 | For Linux, you need "perf". On Debian/Ubuntu, you can install
26 | package "perf-tools-common" to get it. Run "perf" once with no
27 | arguments to check if it requires additional packages to be installed.
28 |
29 | To submit changes to this repository, see http://golang.org/doc/contribute.html.
30 |
31 | [1] https://github.com/golang/proposal/blob/master/design/14313-benchmark-format.md
32 |
--------------------------------------------------------------------------------
/third_party/biogo-examples/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright ©2012 The bíogo Authors. All rights reserved.
2 |
3 | Redistribution and use in source and binary forms, with or without
4 | modification, are permitted provided that the following conditions are met:
5 | * Redistributions of source code must retain the above copyright
6 | notice, this list of conditions and the following disclaimer.
7 | * Redistributions in binary form must reproduce the above copyright
8 | notice, this list of conditions and the following disclaimer in the
9 | documentation and/or other materials provided with the distribution.
10 | * Neither the name of the bíogo project nor the names of its authors and
11 | contributors may be used to endorse or promote products derived from this
12 | software without specific prior written permission.
13 |
14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
15 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 |
--------------------------------------------------------------------------------
/sweet/common/diagnostics/driver.go:
--------------------------------------------------------------------------------
1 | // Copyright 2023 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package diagnostics
6 |
7 | import (
8 | "flag"
9 | "fmt"
10 | )
11 |
12 | // DriverConfig is a diagnostics configuration that can be passed to a benchmark
13 | // driver by serializing to and from command-line flags.
14 | type DriverConfig struct {
15 | ConfigSet
16 | ResultsDir string
17 | }
18 |
19 | // DriverArgs returns the arguments that should be passed to a Sweet benchmark
20 | // binary to collect data for c.
21 | func (c *DriverConfig) DriverArgs() []string {
22 | args := []string{"-results-dir", c.ResultsDir}
23 | for _, c1 := range c.cfgs {
24 | args = append(args, "-"+string(c1.Type))
25 | if c1.Type == Perf {
26 | // String flag
27 | args = append(args, c1.Flags)
28 | }
29 | }
30 | return args
31 | }
32 |
33 | // AddFlags populates f with flags that will fill in c.
34 | func (c *DriverConfig) AddFlags(f *flag.FlagSet) {
35 | *c = DriverConfig{}
36 | c.ConfigSet.cfgs = make(map[Type]Config)
37 |
38 | f.StringVar(&c.ResultsDir, "results-dir", "", "directory to write diagnostics data")
39 | for _, t := range Types() {
40 | t := t
41 | if t == Perf {
42 | f.Func(string(t), fmt.Sprintf("enable %s diagnostics with `flags`", t), func(s string) error {
43 | c.cfgs[t] = Config{Type: t, Flags: s}
44 | return nil
45 | })
46 | } else {
47 | f.BoolFunc(string(t), fmt.Sprintf("enable %s diagnostics", t), func(s string) error {
48 | c.cfgs[t] = Config{Type: t}
49 | return nil
50 | })
51 | }
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/third_party/biogo-examples/igor/igor/pile.go:
--------------------------------------------------------------------------------
1 | // Copyright ©2014 The bíogo Authors. All rights reserved.
2 | // Copyright 2021 The Go Authors. All rights reserved.
3 | // Use of this source code is governed by a BSD-style
4 | // license that can be found in the LICENSE file.
5 |
6 | package igor
7 |
8 | import (
9 | "github.com/biogo/biogo/align/pals"
10 | "github.com/biogo/biogo/io/featio"
11 | "github.com/biogo/biogo/io/featio/gff"
12 | )
13 |
14 | // store is a pals.Contig internment implementation.
15 | type store map[pals.Contig]pals.Contig
16 |
17 | // intern returns an interned copy of the parameter.
18 | func (is store) intern(c pals.Contig) pals.Contig {
19 | if c == "" {
20 | return ""
21 | }
22 | t, ok := is[c]
23 | if ok {
24 | return t
25 | }
26 | is[c] = c
27 | return c
28 | }
29 |
30 | // Piles reads the features in the input gff.Reader and applies pals.Piler analysis
31 | // using the specified overlap and pair filter function. The features in the input
32 | // must satisfy pals.ExpandFeature restrictions.
33 | func Piles(in *gff.Reader, overlap int, pf pals.PairFilter) ([]*pals.Pile, error) {
34 | piler := pals.NewPiler(overlap)
35 | contigs := make(store)
36 |
37 | var n int
38 |
39 | sc := featio.NewScanner(in)
40 | for sc.Next() {
41 | rep := sc.Feat().(*gff.Feature)
42 |
43 | p, err := pals.ExpandFeature(rep)
44 | if err != nil {
45 | return nil, err
46 | }
47 | p.A.Loc = contigs.intern(p.A.Loc.(pals.Contig))
48 | p.B.Loc = contigs.intern(p.B.Loc.(pals.Contig))
49 |
50 | piler.Add(p)
51 | n++
52 | }
53 | if err := sc.Error(); err != nil {
54 | return nil, err
55 | }
56 | return piler.Piles(pf), nil
57 | }
58 |
--------------------------------------------------------------------------------
/sweet/benchmarks/markdown/main.go:
--------------------------------------------------------------------------------
1 | // Copyright 2021 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package main
6 |
7 | import (
8 | "bytes"
9 | "flag"
10 | "fmt"
11 | "os"
12 | "path/filepath"
13 |
14 | "golang.org/x/benchmarks/sweet/benchmarks/internal/driver"
15 |
16 | "gitlab.com/golang-commonmark/markdown"
17 | )
18 |
19 | func run(mddir string) error {
20 | files, err := os.ReadDir(mddir)
21 | if err != nil {
22 | return err
23 | }
24 |
25 | contents := make([][]byte, 0, len(files))
26 | for _, file := range files {
27 | if !file.IsDir() && filepath.Ext(file.Name()) == ".md" {
28 | content, err := os.ReadFile(filepath.Join(mddir, file.Name()))
29 | if err != nil {
30 | return err
31 | }
32 | contents = append(contents, content)
33 | }
34 | }
35 |
36 | out := bytes.Buffer{}
37 | out.Grow(1024 * 1024)
38 |
39 | md := markdown.New(
40 | markdown.XHTMLOutput(true),
41 | markdown.Tables(true),
42 | markdown.MaxNesting(8),
43 | markdown.Typographer(true),
44 | markdown.Linkify(true),
45 | )
46 |
47 | return driver.RunBenchmark("MarkdownRenderXHTML", func(_ *driver.B) error {
48 | for _, c := range contents {
49 | md.Render(&out, c)
50 | out.Reset()
51 | }
52 | return nil
53 | }, driver.InProcessMeasurementOptions...)
54 | }
55 |
56 | func main() {
57 | driver.SetFlags(flag.CommandLine)
58 | flag.Parse()
59 | if flag.NArg() != 1 {
60 | fmt.Fprintln(os.Stderr, "expected asset directory as input")
61 | os.Exit(1)
62 | }
63 | if err := run(flag.Arg(0)); err != nil {
64 | fmt.Fprintln(os.Stderr, err)
65 | os.Exit(1)
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/sweet/common/profile/profile.go:
--------------------------------------------------------------------------------
1 | // Copyright 2022 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // Package profile supports working with pprof profiles.
6 | package profile
7 |
8 | import (
9 | "fmt"
10 | "os"
11 | "path/filepath"
12 |
13 | "github.com/google/pprof/profile"
14 | )
15 |
16 | func ReadPprof(filename string) (*profile.Profile, error) {
17 | f, err := os.Open(filename)
18 | if err != nil {
19 | return nil, err
20 | }
21 | defer f.Close()
22 | return profile.Parse(f)
23 | }
24 |
25 | func WritePprof(filename string, p *profile.Profile) error {
26 | f, err := os.Create(filename)
27 | if err != nil {
28 | return err
29 | }
30 | defer f.Close()
31 |
32 | err = p.Write(f)
33 | if err == nil {
34 | err = f.Close()
35 | }
36 | if err != nil {
37 | return fmt.Errorf("error writing profile %s: %s", filename, err)
38 | }
39 |
40 | return nil
41 | }
42 |
43 | // ReadDirPprof reads all pprof profiles in dir whose name matches match(name).
44 | func ReadDirPprof(dir string, match func(string) bool) ([]*profile.Profile, error) {
45 | entries, err := os.ReadDir(dir)
46 | if err != nil {
47 | return nil, err
48 | }
49 | var profiles []*profile.Profile
50 | for _, entry := range entries {
51 | name := entry.Name()
52 | path := filepath.Join(dir, name)
53 | if info, err := entry.Info(); err != nil {
54 | return nil, err
55 | } else if info.Size() == 0 {
56 | // Skip zero-sized files, otherwise the pprof package
57 | // will call it a parsing error.
58 | continue
59 | }
60 | if match(name) {
61 | p, err := ReadPprof(path)
62 | if err != nil {
63 | return nil, err
64 | }
65 | profiles = append(profiles, p)
66 | continue
67 | }
68 | }
69 | return profiles, nil
70 | }
71 |
--------------------------------------------------------------------------------
/json/json.go:
--------------------------------------------------------------------------------
1 | // Copyright 2013 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // JSON benchmark marshals and unmarshals ~2MB json string
6 | // with a tree-like object hierarchy, in 4*GOMAXPROCS goroutines.
7 | package main
8 |
9 | import (
10 | "bytes"
11 | "compress/bzip2"
12 | "encoding/base64"
13 | "encoding/json"
14 | "io"
15 |
16 | "golang.org/x/benchmarks/driver"
17 | )
18 |
19 | func main() {
20 | driver.Main("JSON", benchmark)
21 | }
22 |
23 | func benchmark() driver.Result {
24 | return driver.Benchmark(benchmarkN)
25 | }
26 |
27 | func benchmarkN(N uint64) {
28 | driver.Parallel(N, 4, func() {
29 | var r Response
30 | if err := json.Unmarshal(jsonbytes, &r); err != nil {
31 | panic(err)
32 | }
33 | if _, err := json.Marshal(&jsondata); err != nil {
34 | panic(err)
35 | }
36 | })
37 | }
38 |
39 | var (
40 | jsonbytes = makeBytes()
41 | jsondata = makeData()
42 | )
43 |
44 | func makeBytes() []byte {
45 | var r io.Reader
46 | r = bytes.NewReader(bytes.Replace(jsonbz2_base64, []byte{'\n'}, nil, -1))
47 | r = base64.NewDecoder(base64.StdEncoding, r)
48 | r = bzip2.NewReader(r)
49 | b, err := io.ReadAll(r)
50 | if err != nil {
51 | panic(err)
52 | }
53 | return b
54 | }
55 |
56 | func makeData() Response {
57 | var v Response
58 | if err := json.Unmarshal(jsonbytes, &v); err != nil {
59 | panic(err)
60 | }
61 | return v
62 | }
63 |
64 | type Response struct {
65 | Tree *Node `json:"tree"`
66 | Username string `json:"username"`
67 | }
68 |
69 | type Node struct {
70 | Name string `json:"name"`
71 | Kids []*Node `json:"kids"`
72 | CLWeight float64 `json:"cl_weight"`
73 | Touches int `json:"touches"`
74 | MinT int64 `json:"min_t"`
75 | MaxT int64 `json:"max_t"`
76 | MeanT int64 `json:"mean_t"`
77 | }
78 |
--------------------------------------------------------------------------------
/sweet/cmd/sweet/put.go:
--------------------------------------------------------------------------------
1 | // Copyright 2021 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package main
6 |
7 | import (
8 | "flag"
9 | "fmt"
10 | "io"
11 | "os"
12 | "os/exec"
13 |
14 | "golang.org/x/benchmarks/sweet/cli/assets"
15 | "golang.org/x/benchmarks/sweet/common"
16 | "golang.org/x/benchmarks/sweet/common/log"
17 | )
18 |
19 | const (
20 | putUsage = `Uploads a new version of the benchmark assets to GCS.
21 |
22 | Usage: %s put [flags]
23 | `
24 | )
25 |
26 | type putCmd struct {
27 | force bool
28 | bucket string
29 | assetsDir string
30 | assetsHashFile string
31 | version string
32 | }
33 |
34 | func (*putCmd) Name() string { return "put" }
35 | func (*putCmd) Synopsis() string {
36 | return "Uploads a new version of the benchmark assets."
37 | }
38 | func (*putCmd) PrintUsage(w io.Writer, base string) {
39 | fmt.Fprintf(w, putUsage, base)
40 | }
41 |
42 | func (c *putCmd) SetFlags(f *flag.FlagSet) {
43 | f.StringVar(&c.version, "version", common.Version, "the version to upload assets for")
44 | f.StringVar(&c.assetsDir, "assets-dir", "./assets", "assets directory to zip and upload")
45 | }
46 |
47 | func (c *putCmd) Run(_ []string) error {
48 | log.SetActivityLog(true)
49 |
50 | if err := assets.ValidateVersion(c.version); err != nil {
51 | return err
52 | }
53 | log.Printf("Uploading %s to CIPD and tagging with version: %s", c.assetsDir, c.version)
54 |
55 | // Just shell out to cipd. The put subcommand is intended to be used by an expert.
56 | createCmd := exec.Command("cipd", "create", "-in", c.assetsDir, "-name", "golang/sweet/assets", "-tag", "version:"+assets.ToCIPDVersion(c.version), "-compression-level", "9")
57 | createCmd.Stdout = os.Stdout
58 | createCmd.Stderr = os.Stderr
59 | if err := createCmd.Run(); err != nil {
60 | return fmt.Errorf("executing `%s`: %v", createCmd, err)
61 | }
62 | return nil
63 | }
64 |
--------------------------------------------------------------------------------
/cmd/bent/configs/configurations-cronjob.toml:
--------------------------------------------------------------------------------
1 | [[Configurations]]
2 | Name = "baseline"
3 | Root = "$ROOT/${BASE}"
4 | AfterBuild = [ "benchsize", "benchdwarf" ]
5 | GcEnv = ["GOARCH=${BENTARCH}"]
6 |
7 | [[Configurations]]
8 | Name = "experiment"
9 | Root = "$ROOT/go-tip/"
10 | AfterBuild = [ "benchsize", "benchdwarf" ]
11 | GcEnv = ["GOARCH=${BENTARCH}"]
12 | RunEnv = ["GOARCH=${BENTARCH}"]
13 |
14 | [[Configurations]]
15 | Name = "baseline-prof"
16 | Root = "$ROOT/${BASE}"
17 | RunWrapper = ["cpuprofile"]
18 | GcEnv = ["GOARCH=${BENTARCH}"]
19 | RunEnv = ["GOARCH=${BENTARCH}"]
20 | Disabled = true
21 |
22 | [[Configurations]]
23 | Name = "experiment-prof"
24 | Root = "$ROOT/go-tip/"
25 | RunWrapper = ["cpuprofile"]
26 | GcEnv = ["GOARCH=${BENTARCH}"]
27 | RunEnv = ["GOARCH=${BENTARCH}"]
28 | Disabled = true
29 |
30 | [[Configurations]]
31 | Name = "experiment-prof-nopreempt"
32 | Root = "$ROOT/go-tip/"
33 | RunWrapper = ["cpuprofile"]
34 | RunEnv = ["GODEBUG=asyncpreemptoff=1", "GOARCH=${BENTARCH}"]
35 | GcEnv = ["GOARCH=${BENTARCH}"]
36 | Disabled = true
37 |
38 | [[Configurations]]
39 | Name = "baseline-Nl"
40 | GcFlags = "-N -l"
41 | Root = "$ROOT/${BASE}"
42 | AfterBuild = [ "benchsize", "benchdwarf" ]
43 | GcEnv = ["GOARCH=${BENTARCH}"]
44 | RunEnv = ["GOARCH=${BENTARCH}"]
45 | Disabled = true
46 |
47 | [[Configurations]]
48 | Name = "experiment-Nl"
49 | GcFlags = "-N -l"
50 | Root = "$ROOT/go-tip/"
51 | AfterBuild = [ "benchsize", "benchdwarf" ]
52 | GcEnv = ["GOARCH=${BENTARCH}"]
53 | RunEnv = ["GOARCH=${BENTARCH}"]
54 | Disabled = true
55 |
56 | [[Configurations]]
57 | Name = "baseline-l"
58 | GcFlags = "-l"
59 | Root = "$ROOT/${BASE}"
60 | AfterBuild = [ "benchsize", "benchdwarf" ]
61 | GcEnv = ["GOARCH=${BENTARCH}"]
62 | RunEnv = ["GOARCH=${BENTARCH}"]
63 | Disabled = true
64 |
65 | [[Configurations]]
66 | Name = "experiment-l"
67 | GcFlags = "-l"
68 | Root = "$ROOT/go-tip/"
69 | AfterBuild = [ "benchsize", "benchdwarf" ]
70 | GcEnv = ["GOARCH=${BENTARCH}"]
71 | RunEnv = ["GOARCH=${BENTARCH}"]
72 | Disabled = true
73 |
--------------------------------------------------------------------------------
/third_party/bleve-bench/mapping.go:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2018 Couchbase, Inc.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | // Copyright 2021 The Go Authors. All rights reserved.
16 | // Use of this source code is governed by a BSD-style
17 | // license that can be found in the LICENSE file.
18 |
19 | //go:build !aix && !plan9 && !wasm
20 |
21 | package blevebench
22 |
23 | import (
24 | "github.com/blevesearch/bleve"
25 | "github.com/blevesearch/bleve/mapping"
26 | )
27 |
28 | // ArticleMapping returns a mapping for indexing wikipedia articles
29 | // in a manner similar to that done by the Apache Lucene nightly
30 | // benchmarks.
31 | func ArticleMapping() mapping.IndexMapping {
32 | standard := bleve.NewTextFieldMapping()
33 | standard.Store = false
34 | standard.IncludeInAll = false
35 | standard.IncludeTermVectors = false
36 | standard.Analyzer = "standard"
37 |
38 | keyword := bleve.NewTextFieldMapping()
39 | keyword.Store = false
40 | keyword.IncludeInAll = false
41 | keyword.IncludeTermVectors = false
42 | keyword.Analyzer = "keyword"
43 |
44 | article := bleve.NewDocumentMapping()
45 | article.AddFieldMappingsAt("Title", keyword)
46 | article.AddFieldMappingsAt("Text", standard)
47 |
48 | disabled := bleve.NewDocumentDisabledMapping()
49 | article.AddSubDocumentMapping("Other", disabled)
50 |
51 | mapping := bleve.NewIndexMapping()
52 | mapping.DefaultMapping = article
53 | mapping.DefaultField = "Other"
54 | mapping.DefaultAnalyzer = "standard"
55 |
56 | return mapping
57 | }
58 |
59 | type Article struct {
60 | Title, Text string
61 | }
62 |
--------------------------------------------------------------------------------
/sweet/benchmarks/biogo-krishna/krishna.go:
--------------------------------------------------------------------------------
1 | // Copyright 2021 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // krishna is a pure Go implementation of Edgar and Myers PALS tool.
6 | // This version of krishna is modified from its original form and only
7 | // computes alignment for a sequence against itself.
8 | package main
9 |
10 | import (
11 | "bytes"
12 | "flag"
13 | "log"
14 | "runtime"
15 |
16 | "golang.org/x/benchmarks/sweet/benchmarks/internal/driver"
17 | "golang.org/x/benchmarks/third_party/biogo-examples/krishna"
18 |
19 | "github.com/biogo/biogo/align/pals"
20 | )
21 |
22 | const (
23 | minHitLen = 400
24 | minId = 0.94
25 | tubeOffset = 0
26 | tmpChunk = 1e6
27 | )
28 |
29 | var (
30 | alignconc bool
31 | tmpDir string
32 | tmpConcurrent bool
33 | )
34 |
35 | func init() {
36 | driver.SetFlags(flag.CommandLine)
37 | flag.BoolVar(&alignconc, "alignconc", false, "whether to perform alignment concurrently (2 threads)")
38 | flag.StringVar(&tmpDir, "tmp", "", "directory to store temporary files")
39 | flag.BoolVar(&tmpConcurrent, "tmpconc", false, "whether to process morass concurrently")
40 | }
41 |
42 | func main() {
43 | flag.Parse()
44 | log.SetFlags(0)
45 |
46 | if flag.NArg() != 1 {
47 | log.Fatal("error: input FASTA target sequence required")
48 | }
49 | k, err := krishna.New(flag.Arg(0), tmpDir, krishna.Params{
50 | TmpChunkSize: tmpChunk,
51 | MinHitLen: minHitLen,
52 | MinHitId: minId,
53 | TubeOffset: tubeOffset,
54 | AlignConc: alignconc,
55 | TmpConc: tmpConcurrent,
56 | })
57 | if err != nil {
58 | log.Fatalf("error: %v", err)
59 | }
60 | defer k.CleanUp()
61 | err = driver.RunBenchmark("BiogoKrishna", func(d *driver.B) error {
62 | runtime.GC()
63 |
64 | // Make initial buffer size 1 MiB.
65 | b := bytes.Buffer{}
66 | b.Grow(1024 * 1024)
67 | writer := pals.NewWriter(&b, 2, 60, false)
68 | d.ResetTimer()
69 |
70 | return k.Run(writer)
71 | }, driver.InProcessMeasurementOptions...)
72 | if err != nil {
73 | log.Fatalf("error: %v", err)
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/sweet/benchmarks/biogo-igor/igor.go:
--------------------------------------------------------------------------------
1 | // Copyright 2021 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // igor is a tool that takes pairwise alignment data as produced by PALS or krishna
6 | // and reports repeat feature family groupings in JSON format.
7 | package main
8 |
9 | import (
10 | "bytes"
11 | "flag"
12 | "fmt"
13 | "log"
14 | "os"
15 | "runtime"
16 |
17 | "golang.org/x/benchmarks/sweet/benchmarks/internal/driver"
18 | "golang.org/x/benchmarks/third_party/biogo-examples/igor/igor"
19 |
20 | "github.com/biogo/biogo/align/pals"
21 | "github.com/biogo/biogo/io/featio/gff"
22 | )
23 |
24 | const (
25 | band = 0.05
26 | mergeOverlap = 0
27 | removeOverlap = 0.95
28 | requiredCover = 0.95
29 | strictness = 0
30 |
31 | pileDiff = 0.05
32 | imageDiff = 0.05
33 | )
34 |
35 | func main() {
36 | driver.SetFlags(flag.CommandLine)
37 | flag.Parse()
38 | log.SetFlags(0)
39 |
40 | if flag.NArg() != 1 {
41 | log.Fatal("error: input GFF file required")
42 | }
43 |
44 | data, err := os.ReadFile(flag.Arg(0))
45 | if err != nil {
46 | log.Fatalf("error: %v", err)
47 | }
48 | err = driver.RunBenchmark("BiogoIgor", func(_ *driver.B) error {
49 | r := bytes.NewReader(data)
50 | in := gff.NewReader(r)
51 |
52 | out := bytes.Buffer{}
53 | out.Grow(1024 * 1024)
54 |
55 | var pf pals.PairFilter
56 | piles, err := igor.Piles(in, mergeOverlap, pf)
57 | if err != nil {
58 | return fmt.Errorf("piling: %v", err)
59 | }
60 |
61 | _, clusters := igor.Cluster(piles, igor.ClusterConfig{
62 | BandWidth: band,
63 | RequiredCover: requiredCover,
64 | OverlapStrictness: strictness,
65 | OverlapThresh: removeOverlap,
66 | Procs: runtime.GOMAXPROCS(0),
67 | })
68 | cc := igor.Group(clusters, igor.GroupConfig{
69 | PileDiff: pileDiff,
70 | ImageDiff: imageDiff,
71 | Classic: false,
72 | })
73 | err = igor.WriteJSON(cc, &out)
74 | if err != nil {
75 | return err
76 | }
77 | return nil
78 | }, driver.InProcessMeasurementOptions...)
79 | if err != nil {
80 | log.Fatalf("error: %v", err)
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/cmd/bent/bent_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2021 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | //go:build go1.16
6 |
7 | package main
8 |
9 | import (
10 | "fmt"
11 | "os"
12 | "os/exec"
13 | "runtime"
14 | "testing"
15 | )
16 |
17 | var dir string
18 |
19 | // TestMain implemented to allow (1) alternate use as bent command itself if BENT_TEST_IS_CMD_BENT is in environment,
20 | // and (2) to create and remove a temporary directory for test initialization.
21 | func TestMain(m *testing.M) {
22 | if os.Getenv("BENT_TEST_IS_CMD_BENT") != "" {
23 | main()
24 | os.Exit(0)
25 | }
26 | var err error
27 | dir, err = os.MkdirTemp("", "bent_test")
28 | if err != nil {
29 | fmt.Fprintln(os.Stderr, err)
30 | os.Exit(1)
31 | }
32 | defer os.RemoveAll(dir)
33 | m.Run()
34 | }
35 |
36 | // bentCmd returns a "bent" command (that is implemented by rerunning the current program after setting
37 | // BENT_TEST_IS_CMD_BENT). The command is always run in the temporary directory created by TestMain.
38 | func bentCmd(t *testing.T, args ...string) *exec.Cmd {
39 | exe, err := os.Executable()
40 | if err != nil {
41 | t.Fatal(err)
42 | }
43 | cmd := exec.Command(exe, args...)
44 | cmd.Dir = dir
45 | cmd.Env = append(os.Environ(), "BENT_TEST_IS_CMD_BENT=1", "PWD="+dir)
46 | return cmd
47 | }
48 |
49 | func TestBent(t *testing.T) {
50 | if runtime.GOARCH == "wasm" {
51 | t.Skipf("skipping test: exec not supported on %s/%s", runtime.GOOS, runtime.GOARCH)
52 | }
53 | cmd := bentCmd(t, "-I")
54 | output, err := cmd.CombinedOutput()
55 | if err != nil {
56 | fmt.Fprintf(os.Stderr, "%s\n", output)
57 | t.Fatal(err)
58 | }
59 | t.Log(string(output))
60 | Cs := []string{"sample", "cronjob", "cmpjob", "gollvm"}
61 | Bs := []string{"all", "50", "gc", "gcplus", "trial"}
62 | for _, c := range Cs {
63 | for _, b := range Bs {
64 | cmd = bentCmd(t, "-l", "-C=configurations-"+c+".toml", "-B=benchmarks-"+b+".toml")
65 | output, err = cmd.CombinedOutput()
66 | if err != nil {
67 | fmt.Fprintf(os.Stderr, "%s\n", output)
68 | t.Fatal(err)
69 | }
70 | t.Log(string(output))
71 | }
72 | Bs = Bs[:1] // truncate Bs for remaining configurations
73 | }
74 |
75 | }
76 |
--------------------------------------------------------------------------------
/cmd/bent/scripts/cmpcl-phase.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash -x
2 |
3 | # Variant of cmpcl.sh for comparing SSA phase timings for a CL and its immediate predecessor.
4 |
5 | # git fetch "https://go.googlesource.com/go" refs/changes/61/196661/3 && git checkout FETCH_HEAD
6 |
7 | if [ $# -lt 1 ] ; then
8 | echo cmpcl.sh "refs/changes///" "bent-options"
9 | exit 1
10 | fi
11 |
12 | if [ ${1:0:1} = "-" ] ; then
13 | echo "First parameter should be a git tag or branch"
14 | exit 1
15 | fi
16 |
17 | cl="$1"
18 | shift
19 |
20 | ROOT=`pwd`
21 | export ROOT cl
22 |
23 | # perflock is not always available
24 | PERFLOCK=`which perflock`
25 |
26 | # N is number of benchmarks, B is number of builds
27 | # Can override these with -N= and -a= on command line.
28 | N=0
29 | B=1
30 |
31 | cd "${ROOT}"
32 |
33 | if [ -e go-old ] ; then
34 | rm -rf go-old
35 | fi
36 |
37 | git clone https://go.googlesource.com/go go-old
38 | if [ $? != 0 ] ; then
39 | echo git clone https://go.googlesource.com/go go-old FAILED
40 | exit 1
41 | fi
42 | cd go-old/src
43 | git fetch "https://go.googlesource.com/go" "${cl}"
44 | if [ $? != 0 ] ; then
45 | echo git fetch "https://go.googlesource.com/go" "${cl}" failed
46 | exit 1
47 | fi
48 | git checkout FETCH_HEAD^1
49 | if [ $? != 0 ] ; then
50 | echo git checkout FETCH_HEAD^1 failed
51 | exit 1
52 | fi
53 | ./make.bash
54 | if [ $? != 0 ] ; then
55 | echo BASE make.bash FAILED
56 | exit 1
57 | fi
58 | oldtag=`git log -n 1 --format='%h'`
59 | export oldtag
60 |
61 | cd "${ROOT}"
62 |
63 | if [ -e go-new ] ; then
64 | rm -rf go-new
65 | fi
66 | git clone https://go.googlesource.com/go go-new
67 | if [ $? != 0 ] ; then
68 | echo git clone go-new failed
69 | exit 1
70 | fi
71 | cd go-new/src
72 |
73 | git fetch "https://go.googlesource.com/go" "${cl}"
74 | if [ $? != 0 ] ; then
75 | echo git fetch "https://go.googlesource.com/go" "${cl}" failed
76 | exit 1
77 | fi
78 | git checkout FETCH_HEAD
79 | if [ $? != 0 ] ; then
80 | echo git checkout FETCH_HEAD failed
81 | exit 1
82 | fi
83 |
84 | ./make.bash
85 | if [ $? != 0 ] ; then
86 | echo make.bash failed
87 | exit 1
88 | fi
89 | newtag=`git log -n 1 --format='%h'`
90 | export newtag
91 |
92 | STAMP="$$"
93 | export STAMP
94 |
95 | cd "${ROOT}"
96 | ${PERFLOCK} bent -v -N=${N} -a=${B} -L=bentjobs.log -c=Old-phase,New-phase -C=configurations-cmpjob.toml "$@" | tee phases.${STAMP}.log
97 | phase-times > phases.${STAMP}.csv
98 |
99 |
--------------------------------------------------------------------------------
/stats/itree.go:
--------------------------------------------------------------------------------
1 | // Copyright 2021 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package stats
6 |
7 | import (
8 | "math"
9 | )
10 |
11 | // IntervalTree is a structure used to make a calculation of running medians quick.
12 | // The structure is described in the Section 8/Appendix of the paper.
13 | type IntervalTree struct {
14 | d int
15 | vals []int
16 | }
17 |
18 | // NewIntervalTree creates a new IntervalTree of depth d.
19 | func NewIntervalTree(d int) *IntervalTree {
20 | if d < 0 {
21 | panic("invalid depth")
22 | }
23 | return &IntervalTree{
24 | d: d,
25 | vals: make([]int, (1<<(d+1))-1),
26 | }
27 | }
28 |
29 | // walk is a generic function on interval trees to add or remove elements.
30 | func (it *IntervalTree) walk(v float64, update int) {
31 | v = math.Abs(v)
32 | mid, inc := 0.5, 0.25
33 | idx := 0
34 | // Update the levels in the tree.
35 | for i := 0; i <= it.d; i++ {
36 | it.vals[idx] += update
37 | idx = idx*2 + 1
38 | if v > mid {
39 | mid += inc
40 | idx += 1
41 | } else {
42 | mid -= inc
43 | }
44 | inc /= 2.
45 | }
46 | }
47 |
48 | // Insert puts an element in an interval tree.
49 | func (it *IntervalTree) Insert(v float64) {
50 | it.walk(v, 1)
51 | }
52 |
53 | // Remove removes an element from an interval tree.
54 | func (it *IntervalTree) Remove(v float64) {
55 | it.walk(v, -1)
56 | }
57 |
58 | // Median returns the current median.
59 | func (it *IntervalTree) Median() float64 {
60 | // If empty, special case and return 0.
61 | numElements := it.NumElements()
62 | if numElements == 0 {
63 | return 0
64 | }
65 |
66 | l, u := 0., 1.
67 | k := int(math.Ceil(float64(numElements) / 2.))
68 | for i := 0; i < len(it.vals); {
69 | j := 2*i + 1
70 | if j >= len(it.vals) {
71 | break
72 | }
73 | if it.vals[i] == k {
74 | kf := float64(k)
75 | a, b := float64(it.vals[j])/kf, float64(it.vals[j+1])/kf
76 | x := (l + (l+u)/2.) / 2.
77 | y := (u + (l+u)/2.) / 2.
78 | return (a*x + b*y) / (a + b)
79 | }
80 | if v := it.vals[j]; v >= k {
81 | i = j
82 | u = (l + u) / 2.
83 | } else {
84 | k -= v
85 | i = j + 1
86 | l = (l + u) / 2.
87 | }
88 | }
89 | return (u-l)/2. + l
90 | }
91 |
92 | // NumElements returns the number of elements in the tree.
93 | func (it *IntervalTree) NumElements() int {
94 | return it.vals[0]
95 | }
96 |
--------------------------------------------------------------------------------
/sweet/benchmarks/gvisor/common.go:
--------------------------------------------------------------------------------
1 | // Copyright 2021 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | //go:build linux
6 |
7 | package main
8 |
9 | import (
10 | "fmt"
11 | "os"
12 | "os/exec"
13 | "path/filepath"
14 | "syscall"
15 |
16 | "golang.org/x/benchmarks/sweet/benchmarks/internal/driver"
17 | "golang.org/x/benchmarks/sweet/common"
18 | "golang.org/x/benchmarks/sweet/common/diagnostics"
19 | )
20 |
21 | func workloadsPath(assetsDir, subBenchmark string) string {
22 | p := common.CurrentPlatform()
23 | platformDir := fmt.Sprintf("%s-%s", p.GOOS, p.GOARCH)
24 | return filepath.Join(assetsDir, subBenchmark, "bin", platformDir, "workload")
25 | }
26 |
27 | func (cfg *config) runscCmd(arg ...string) (*exec.Cmd, []func()) {
28 | var cmd *exec.Cmd
29 |
30 | cmdArgs := []string{cfg.runscPath}
31 |
32 | goProfiling := false
33 | var postExit []func()
34 | addDiagnostic := func(typ diagnostics.Type, flag string) {
35 | if df, err := cfg.diag.Create(typ); err != nil {
36 | fmt.Fprintf(os.Stderr, "failed to create %s diagnostics: %s\n", typ, err)
37 | } else if df != nil {
38 | df.Close()
39 | cmdArgs = append(cmdArgs, flag, df.Name())
40 | goProfiling = true
41 | postExit = append(postExit, df.Commit)
42 | }
43 | }
44 | addDiagnostic(diagnostics.CPUProfile, "-profile-cpu")
45 | addDiagnostic(diagnostics.MemProfile, "-profile-heap")
46 | addDiagnostic(diagnostics.Trace, "-trace")
47 | if goProfiling {
48 | cmdArgs = append(cmdArgs, "-profile")
49 | }
50 |
51 | if df, err := cfg.diag.Create(diagnostics.Perf); err != nil {
52 | fmt.Fprintf(os.Stderr, "failed to create %s diagnostics: %s\n", diagnostics.Perf, err)
53 | } else if df != nil {
54 | df.Close()
55 | postExit = append(postExit, df.Commit)
56 |
57 | perfArgs := []string{"perf", "record", "-o", df.Name()}
58 | perfArgs = append(perfArgs, driver.PerfFlags()...)
59 | perfArgs = append(perfArgs, cmdArgs...)
60 | cmdArgs = perfArgs
61 | }
62 |
63 | cmdArgs = append(cmdArgs, arg...)
64 | cmd = exec.Command(cmdArgs[0], cmdArgs[1:]...)
65 | cmd.SysProcAttr = &syscall.SysProcAttr{
66 | // Try to bring down the sandbox if we unexpectedly exit.
67 | Pdeathsig: syscall.SIGKILL,
68 |
69 | // New process group, so we can kill the entire sub-process
70 | // tree at once.
71 | Setpgid: true,
72 | }
73 | return cmd, postExit
74 | }
75 |
--------------------------------------------------------------------------------
/sweet/benchmarks/internal/pool/pool_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2021 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package pool
6 |
7 | import (
8 | "context"
9 | "io"
10 | "testing"
11 | )
12 |
13 | func TestEmptyPool(t *testing.T) {
14 | p := New(context.Background(), []Worker{})
15 | if err := p.Run(); err != nil {
16 | t.Fatalf("got error from empty pool: %v", err)
17 | }
18 | }
19 |
20 | type countCloser struct {
21 | c int
22 | }
23 |
24 | func (c *countCloser) Close() error {
25 | c.c++
26 | return nil
27 | }
28 |
29 | type boolWorker struct {
30 | countCloser
31 | exec bool
32 | }
33 |
34 | func (b *boolWorker) Run(_ context.Context) error {
35 | b.exec = true
36 | return Done
37 | }
38 |
39 | func TestPool(t *testing.T) {
40 | workers := []Worker{
41 | &boolWorker{},
42 | &boolWorker{},
43 | &boolWorker{},
44 | &boolWorker{},
45 | }
46 | p := New(context.Background(), workers)
47 | if err := p.Run(); err != nil {
48 | t.Fatalf("got error from good pool: %v", err)
49 | }
50 | for _, w := range workers {
51 | if !w.(*boolWorker).exec {
52 | t.Fatal("found worker that was never executed")
53 | }
54 | }
55 | }
56 |
57 | type badWorker struct {
58 | countCloser
59 | }
60 |
61 | func (b *badWorker) Run(_ context.Context) error {
62 | return io.EOF
63 | }
64 |
65 | func TestPoolError(t *testing.T) {
66 | workers := []Worker{
67 | &boolWorker{},
68 | &boolWorker{},
69 | &boolWorker{},
70 | &badWorker{},
71 | }
72 | p := New(context.Background(), workers)
73 | if err := p.Run(); err == nil {
74 | t.Fatal("expected error from bad worker")
75 | } else if err != io.EOF {
76 | t.Fatalf("unexpected error from pool: %v", err)
77 | }
78 | }
79 |
80 | type foreverWorker struct {
81 | countCloser
82 | }
83 |
84 | func (f *foreverWorker) Run(ctx context.Context) error {
85 | return nil
86 | }
87 |
88 | func TestPoolCancel(t *testing.T) {
89 | workers := []Worker{
90 | &foreverWorker{},
91 | &foreverWorker{},
92 | &foreverWorker{},
93 | &foreverWorker{},
94 | }
95 | ctx := context.Background()
96 | ctx, cancel := context.WithCancel(ctx)
97 | p := New(ctx, workers)
98 | cancel()
99 | if err := p.Run(); err != nil {
100 | t.Fatalf("got error from good pool: %v", err)
101 | }
102 | }
103 |
--------------------------------------------------------------------------------
/sweet/harnesses/gvisor.go:
--------------------------------------------------------------------------------
1 | // Copyright 2021 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package harnesses
6 |
7 | import (
8 | "fmt"
9 | "os"
10 | "os/exec"
11 | "path/filepath"
12 | "runtime"
13 |
14 | "golang.org/x/benchmarks/sweet/common"
15 | "golang.org/x/benchmarks/sweet/common/log"
16 | )
17 |
18 | type GVisor struct{}
19 |
20 | func (h GVisor) CheckPrerequisites() error {
21 | if runtime.GOOS != "linux" {
22 | return fmt.Errorf("requires Linux")
23 | }
24 | if runtime.GOARCH != "amd64" {
25 | return fmt.Errorf("requires amd64")
26 | }
27 | return nil
28 | }
29 |
30 | func (h GVisor) Get(gcfg *common.GetConfig) error {
31 | return gitCloneToCommit(
32 | gcfg.SrcDir,
33 | "https://github.com/google/gvisor",
34 | "go",
35 | "b75aeea", // release-20240513.0-37-g4f08fc481
36 | )
37 | }
38 |
39 | func (h GVisor) Build(cfg *common.Config, bcfg *common.BuildConfig) error {
40 | // Build benchmarking client which will handle a bunch of coordination.
41 | if err := cfg.GoTool(bcfg.BuildLog).BuildPath(filepath.Join(bcfg.BenchDir), filepath.Join(bcfg.BinDir, "gvisor-bench")); err != nil {
42 | return err
43 | }
44 |
45 | // Build the runsc package in the repository. CGO_ENABLED must be 0.
46 | // See https://github.com/google/gvisor#using-go-get.
47 | cfg.BuildEnv.Env = cfg.BuildEnv.MustSet("CGO_ENABLED=0")
48 | bin := filepath.Join(bcfg.BinDir, "runsc")
49 | if err := cfg.GoTool(bcfg.BuildLog).BuildPath(filepath.Join(bcfg.SrcDir, "runsc"), bin); err != nil {
50 | return err
51 | }
52 |
53 | // Make sure the binary has all the right permissions set.
54 | // See https://gvisor.dev/docs/user_guide/install/#install-directly
55 | log.CommandPrintf("chmod 755 %s", bin)
56 | if err := os.Chmod(bin, 0755); err != nil {
57 | return fmt.Errorf("failed to set permissions on runsc: %w", err)
58 | }
59 | return nil
60 | }
61 |
62 | func (h GVisor) Run(cfg *common.Config, rcfg *common.RunConfig) error {
63 | args := append(rcfg.Args, []string{
64 | "-runsc", filepath.Join(rcfg.BinDir, "runsc"),
65 | "-assets-dir", rcfg.AssetsDir,
66 | "-tmp", rcfg.TmpDir,
67 | }...)
68 | if rcfg.Short {
69 | args = append(args, "-short")
70 | }
71 | cmd := exec.Command(
72 | filepath.Join(rcfg.BinDir, "gvisor-bench"),
73 | args...,
74 | )
75 | cmd.Env = cfg.ExecEnv.Collapse()
76 | cmd.Stdout = rcfg.Results
77 | cmd.Stderr = rcfg.Log
78 | log.TraceCommand(cmd, false)
79 | return cmd.Run()
80 | }
81 |
--------------------------------------------------------------------------------
/sweet/benchmarks/gvisor/main.go:
--------------------------------------------------------------------------------
1 | // Copyright 2021 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | //go:build linux
6 |
7 | package main
8 |
9 | import (
10 | "bytes"
11 | "flag"
12 | "fmt"
13 | "io"
14 | "os"
15 | "runtime/debug"
16 | "time"
17 |
18 | "golang.org/x/benchmarks/sweet/benchmarks/internal/driver"
19 | )
20 |
21 | type config struct {
22 | runscPath string
23 | assetsDir string
24 | tmpDir string
25 | short bool
26 |
27 | diag *driver.Diagnostics
28 | }
29 |
30 | var cliCfg config
31 |
32 | func init() {
33 | driver.SetFlags(flag.CommandLine)
34 | flag.StringVar(&cliCfg.runscPath, "runsc", "", "path to the runsc binary")
35 | flag.StringVar(&cliCfg.assetsDir, "assets-dir", "", "path to the directory containing benchmark root filesystems")
36 | flag.StringVar(&cliCfg.tmpDir, "tmp", "", "path to a temporary working directory")
37 | flag.BoolVar(&cliCfg.short, "short", false, "whether to run a short version of the benchmarks")
38 | }
39 |
40 | type benchmark interface {
41 | name() string
42 | run(*config, io.Writer) error
43 | }
44 |
45 | func main1() error {
46 | benchmarks := []benchmark{
47 | // TODO(go.dev/issue/67508): Disable the startup benchmark because it doesn't work
48 | // on the builders.
49 | // startup{},
50 | systemCall{500000},
51 | httpServer{20 * time.Second},
52 | }
53 | if cliCfg.short {
54 | benchmarks = []benchmark{
55 | // TODO(go.dev/issue/67508): Disable the startup benchmark because it doesn't work
56 | // on the builders.
57 | // startup{},
58 | systemCall{500},
59 | httpServer{1 * time.Second},
60 | }
61 | }
62 |
63 | // Run each benchmark once.
64 | for _, bench := range benchmarks {
65 | cfg := cliCfg
66 | cfg.diag = driver.NewDiagnostics(bench.name())
67 |
68 | // Run the benchmark command under runsc.
69 | var buf bytes.Buffer
70 | if err := bench.run(&cfg, &buf); err != nil {
71 | if buf.Len() != 0 {
72 | fmt.Fprintf(os.Stderr, "=== Benchmark %s stdout+stderr ===", bench.name())
73 | fmt.Fprintf(os.Stderr, "%s\n", buf.String())
74 | }
75 | return err
76 | }
77 |
78 | cfg.diag.Commit(nil)
79 | }
80 | return nil
81 | }
82 |
83 | func main() {
84 | debug.SetTraceback("all")
85 |
86 | flag.Parse()
87 | if flag.NArg() != 0 {
88 | fmt.Fprintf(os.Stderr, "error: unexpected args\n")
89 | os.Exit(1)
90 | }
91 | if err := main1(); err != nil {
92 | fmt.Fprintf(os.Stderr, "error: %v\n", err)
93 | os.Exit(1)
94 | }
95 | }
96 |
--------------------------------------------------------------------------------
/sweet/common/env.go:
--------------------------------------------------------------------------------
1 | // Copyright 2021 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package common
6 |
7 | import (
8 | "fmt"
9 | "os"
10 | "strings"
11 | )
12 |
13 | type Env struct {
14 | parent *Env
15 | data map[string]string
16 | }
17 |
18 | func varsToMap(vars ...string) (map[string]string, error) {
19 | env := make(map[string]string)
20 | for _, v := range vars {
21 | s := strings.SplitN(v, "=", 2)
22 | if len(s) != 2 {
23 | return nil, fmt.Errorf("%q is not a valid environment variable", v)
24 | }
25 | env[s[0]] = s[1]
26 | }
27 | return env, nil
28 | }
29 |
30 | func NewEnvFromEnviron() *Env {
31 | env, err := NewEnv(os.Environ()...)
32 | if err != nil {
33 | panic(err)
34 | }
35 | return env
36 | }
37 |
38 | func NewEnv(vars ...string) (*Env, error) {
39 | m, err := varsToMap(vars...)
40 | if err != nil {
41 | return nil, err
42 | }
43 | return &Env{data: m}, nil
44 | }
45 |
46 | func (e *Env) Set(vars ...string) (*Env, error) {
47 | m, err := varsToMap(vars...)
48 | if err != nil {
49 | return nil, err
50 | }
51 | return &Env{
52 | data: m,
53 | parent: e,
54 | }, nil
55 | }
56 |
57 | func (e *Env) MustSet(vars ...string) *Env {
58 | env, err := e.Set(vars...)
59 | if err != nil {
60 | panic(err)
61 | }
62 | return env
63 | }
64 |
65 | func (e *Env) Lookup(name string) (string, bool) {
66 | t := e
67 | for t != nil {
68 | if v, ok := t.data[name]; ok {
69 | return v, true
70 | }
71 | t = t.parent
72 | }
73 | return "", false
74 | }
75 |
76 | func (e *Env) Prefix(name, prefix string) *Env {
77 | var (
78 | n *Env
79 | err error
80 | )
81 | if v, ok := e.Lookup(name); ok {
82 | n, err = e.Set(fmt.Sprintf("%s=%s%s", name, prefix, v))
83 | } else {
84 | n, err = e.Set(fmt.Sprintf("%s=%s", name, prefix))
85 | }
86 | // If we actually get an error out of Set here, then
87 | // something went very wrong. Panic.
88 | if err != nil {
89 | panic(err.Error())
90 | }
91 | return n
92 | }
93 |
94 | func (e *Env) Collapse() []string {
95 | t := e
96 | c := make(map[string]string)
97 | for t != nil {
98 | for k, v := range t.data {
99 | if _, ok := c[k]; !ok {
100 | c[k] = v
101 | }
102 | }
103 | t = t.parent
104 | }
105 | env := make([]string, 0, len(c))
106 | for k, v := range c {
107 | env = append(env, fmt.Sprintf("%s=%s", k, v))
108 | }
109 | return env
110 | }
111 |
--------------------------------------------------------------------------------
/sweet/common/config_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2021 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package common_test
6 |
7 | import (
8 | "strings"
9 | "testing"
10 |
11 | "github.com/BurntSushi/toml"
12 | "golang.org/x/benchmarks/sweet/common"
13 | )
14 |
15 | func TestConfigMarshalTOML(t *testing.T) {
16 | cfgsBefore := common.ConfigFile{
17 | Configs: []*common.Config{
18 | &common.Config{
19 | Name: "go",
20 | GoRoot: "/path/to/my/goroot",
21 | // The unmarashaler propagates the environment,
22 | // so to make sure this works, let's also seed
23 | // from the environment.
24 | BuildEnv: common.ConfigEnv{common.NewEnvFromEnviron()},
25 | ExecEnv: common.ConfigEnv{common.NewEnvFromEnviron()},
26 | },
27 | },
28 | }
29 | b, err := common.ConfigFileMarshalTOML(&cfgsBefore)
30 | if err != nil {
31 | t.Fatal(err)
32 | }
33 | var cfgsAfter common.ConfigFile
34 | if err := toml.Unmarshal(b, &cfgsAfter); err != nil {
35 | t.Fatal(err)
36 | }
37 | if l := len(cfgsAfter.Configs); l != len(cfgsBefore.Configs) {
38 | t.Fatalf("unexpected number of configs: got %d, want %d", l, len(cfgsBefore.Configs))
39 | }
40 | for i := range cfgsAfter.Configs {
41 | cfgBefore := cfgsBefore.Configs[i]
42 | cfgAfter := cfgsAfter.Configs[i]
43 |
44 | if cfgBefore.Name != cfgAfter.Name {
45 | t.Fatalf("unexpected name: got %s, want %s", cfgAfter.Name, cfgBefore.Name)
46 | }
47 | if cfgBefore.GoRoot != cfgAfter.GoRoot {
48 | t.Fatalf("unexpected GOROOT: got %s, want %s", cfgAfter.GoRoot, cfgBefore.GoRoot)
49 | }
50 | compareEnvs(t, cfgBefore.BuildEnv.Env, cfgAfter.BuildEnv.Env)
51 | compareEnvs(t, cfgBefore.ExecEnv.Env, cfgAfter.ExecEnv.Env)
52 | }
53 | }
54 |
55 | func compareEnvs(t *testing.T, a, b *common.Env) {
56 | t.Helper()
57 |
58 | aIndex := makeEnvIndex(a)
59 | bIndex := makeEnvIndex(b)
60 | for aKey, aVal := range aIndex {
61 | if bVal, ok := bIndex[aKey]; !ok {
62 | t.Errorf("%s in A but not B", aKey)
63 | } else if aVal != bVal {
64 | t.Errorf("%s has value %s A but %s in B", aKey, aVal, bVal)
65 | }
66 | }
67 | for bKey := range bIndex {
68 | if _, ok := aIndex[bKey]; !ok {
69 | t.Errorf("%s in B but not A", bKey)
70 | }
71 | // Don't check values that exist in both. We got that already
72 | // in the first pass.
73 | }
74 | }
75 |
76 | func makeEnvIndex(a *common.Env) map[string]string {
77 | index := make(map[string]string)
78 | for _, s := range a.Collapse() {
79 | d := strings.IndexRune(s, '=')
80 | index[s[:d]] = s[d+1:]
81 | }
82 | return index
83 | }
84 |
--------------------------------------------------------------------------------
/cmd/bent/scripts/benchdwarf:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | x=`which dwarf-goodness`
4 | y=`which optargorder`
5 | z=`which nostmt`
6 | tmp=tmp-bench-dwarf-$$
7 | bench=no
8 |
9 | # make it exist so it can be removed
10 | cat /dev/null > $tmp
11 |
12 | # Measures fraction of input variables to lines that are present
13 | if [ "x$x" = "x" ] ; then
14 | echo "Can get dwarf-goodness command with 'go get github.com/dr2chase/dwarf-goodness/cmd/dwarf-goodness'"
15 | else
16 | dwarf-goodness "$1" > $tmp
17 | # has format #inputs, #present, ratio, difference
18 | inputsquality=`tail -1 $tmp | awk 'BEGIN {FS=","} {print $3}'`
19 | echo "tmp dwarf line quality wc = " `wc -l $tmp`
20 | bench=yes
21 | fi
22 |
23 | # Measures fraction of function arguments that are present at function entry
24 | if [ "x$y" = "x" ] ; then
25 | echo "Can get optargorder command with 'go get github.com/dr2chase/optargorder'"
26 | else
27 | optargorder "$1" > $tmp
28 | # has format nFunctions,argumentError,mixedRegMem,regReuse,tooManyPieces,missingSource,wrongOrder,missingDwarf,duplicated,1-totalErrors/nFunctions
29 | argsquality=`tail -1 $tmp | awk 'BEGIN {FS=","} {print $10}'`
30 | echo "tmp dwarf args quality wc = " `wc -l $tmp`
31 | bench=yes
32 | fi
33 |
34 | # Measures fraction of lines mentioned in dwarf that are tagged as "is_stmt"
35 | if [ "x$z" = "x" ] ; then
36 | echo "Can get nostmt command with 'go get github.com/dr2chase/nostmt'"
37 | else
38 | nostmt -c "$1" > $tmp
39 | # has total,nostmt,1-nostmt/total
40 | stmtquality=`tail -1 $tmp | awk 'BEGIN {FS=","} {print $3}'`
41 | echo "tmp stmt args quality wc = " `wc -l $tmp`
42 |
43 | nostmt -c -k "$1" > $tmp
44 | # has total,nostmt,1-nostmt/total
45 | stmtkindquality=`tail -1 $tmp | awk 'BEGIN {FS=","} {print $3}'`
46 | echo "tmp stmt args kind quality wc = " `wc -l $tmp`
47 |
48 | bench=yes
49 | fi
50 |
51 | if [ ${bench} = "yes" ] ; then
52 | echo "goos: $GOOS"
53 | echo "goarch: $GOARCH"
54 | echo "pkg:" # Erase any inherited pkg if files are concatenated
55 | if echo $inputsquality | egrep -q '[.0-9]+' ; then
56 | echo Unit inputs-quality assume=exact
57 | echo "Benchmark${2}_dwarf_input_goodness" 1 ${inputsquality} inputs-quality
58 | fi
59 | if echo $argsquality | egrep -q '[.0-9]+' ; then
60 | echo Unit args-quality assume=exact
61 | echo "Benchmark${2}_dwarf_args_goodness" 1 ${argsquality} args-quality
62 | fi
63 | if echo $stmtquality | egrep -q '[.0-9]+' ; then
64 | echo Unit stmts-quality assume=exact
65 | echo "Benchmark${2}_dwarf_stmt_goodness" 1 ${stmtquality} stmts-quality
66 | # echo "Benchmark${2}_dwarf_stmt_goodness_kind" 1 ${stmtkindquality} stmts-quality
67 | fi
68 | fi
69 |
70 | rm $tmp
71 |
--------------------------------------------------------------------------------
/driver/driver_plan9.go:
--------------------------------------------------------------------------------
1 | // Copyright 2019 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package driver
6 |
7 | import (
8 | "bytes"
9 | "fmt"
10 | "log"
11 | "os"
12 | "os/exec"
13 | "strconv"
14 | "strings"
15 | "syscall"
16 | "time"
17 | )
18 |
19 | func RunUnderProfiler(args ...string) (string, string) {
20 | return "", ""
21 | }
22 |
23 | // Size runs size command on the file. Returns filename with output. Any errors are ignored.
24 | func Size(file string) string {
25 | return ""
26 | }
27 |
28 | type sysStats struct {
29 | N uint64
30 | CPUTime uint64
31 | }
32 |
33 | func InitSysStats(N uint64) sysStats {
34 | ss := sysStats{N: N}
35 | var err error
36 | ss.CPUTime, err = procCPUTime()
37 | if err != nil {
38 | log.Printf("failed to parse /dev/cputime: %v", err)
39 | ss.N = 0
40 | // Deliberately ignore the error.
41 | }
42 | return ss
43 | }
44 |
45 | func (ss sysStats) Collect(res *Result) {
46 | if ss.N == 0 {
47 | return
48 | }
49 | t, err := procCPUTime()
50 | if err != nil {
51 | log.Printf("failed to parse /dev/cputime: %v", err)
52 | // Deliberately ignore the error.
53 | return
54 | }
55 | res.Metrics["user+sys-ns/op"] = (t - ss.CPUTime) / ss.N
56 | }
57 |
58 | func RunAndCollectSysStats(cmd *exec.Cmd, res *Result, N uint64, prefix string) (string, error) {
59 | var out bytes.Buffer
60 | cmd.Stdout = &out
61 | cmd.Stderr = &out
62 | t0 := time.Now()
63 | if err := cmd.Run(); err != nil {
64 | return out.String(), err
65 | }
66 | t1 := time.Now()
67 | w := cmd.ProcessState.SysUsage().(*syscall.Waitmsg)
68 | res.RunTime = uint64(t1.Sub(t0)) / N
69 | res.Metrics[prefix+"ns/op"] = res.RunTime
70 | res.Metrics[prefix+"user+sys-ns/op"] = cpuTime(w) / N
71 | return out.String(), nil
72 | }
73 |
74 | func procCPUTime() (uint64, error) {
75 | b, err := os.ReadFile("/dev/cputime")
76 | if err != nil {
77 | return 0, err
78 | }
79 | f := strings.Fields(string(b))
80 | if n := len(f); n != 6 {
81 | return 0, fmt.Errorf("/dev/cputime has %v fields", n)
82 | }
83 |
84 | // Sum up time spent in user mode and system calls,
85 | // for both the current process and the descendants.
86 | var tt uint64
87 | for _, i := range []int{0, 1, 3, 4} {
88 | t, err := strconv.ParseUint(f[i], 10, 32)
89 | if err != nil {
90 | return 0, err
91 | }
92 | tt += t
93 | }
94 | return tt * 1e6, nil
95 | }
96 |
97 | func cpuTime(w *syscall.Waitmsg) uint64 {
98 | return uint64(w.Time[0])*1e6 + uint64(w.Time[1])*1e6
99 | }
100 |
101 | func setProcessAffinity(v int) {
102 | }
103 |
--------------------------------------------------------------------------------
/driver/driver_unix.go:
--------------------------------------------------------------------------------
1 | // Copyright 2013 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | //go:build aix || darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris
6 |
7 | package driver
8 |
9 | import (
10 | "bytes"
11 | "log"
12 | "os/exec"
13 | "syscall"
14 | "time"
15 |
16 | "golang.org/x/sys/unix"
17 | )
18 |
19 | type sysStats struct {
20 | N uint64
21 | Rusage unix.Rusage
22 | }
23 |
24 | func InitSysStats(N uint64) sysStats {
25 | ss := sysStats{N: N}
26 | if err := unix.Getrusage(0, &ss.Rusage); err != nil {
27 | log.Printf("Getrusage failed: %v", err)
28 | ss.N = 0
29 | // Deliberately ignore the error.
30 | }
31 | return ss
32 | }
33 |
34 | func (ss sysStats) Collect(res *Result) {
35 | if ss.N == 0 {
36 | return
37 | }
38 | if vm := getVMPeak(); vm != 0 {
39 | res.Metrics["peak-VM-bytes"] = vm
40 | }
41 | usage := new(unix.Rusage)
42 | if err := unix.Getrusage(0, usage); err != nil {
43 | log.Printf("Getrusage failed: %v", err)
44 | // Deliberately ignore the error.
45 | return
46 | }
47 | res.Metrics["peak-RSS-bytes"] = uint64(usage.Maxrss) * rssMultiplier
48 | res.Metrics["user+sys-ns/op"] = (cpuTime(usage) - cpuTime(&ss.Rusage)) / ss.N
49 | }
50 |
51 | func RunAndCollectSysStats(cmd *exec.Cmd, res *Result, N uint64, prefix string) (string, error) {
52 | var out bytes.Buffer
53 | cmd.Stdout = &out
54 | cmd.Stderr = &out
55 | t0 := time.Now()
56 | if err := cmd.Run(); err != nil {
57 | return out.String(), err
58 | }
59 | t1 := time.Now()
60 | usage := fromStdUsage(cmd.ProcessState.SysUsage().(*syscall.Rusage))
61 | res.RunTime = uint64(t1.Sub(t0)) / N
62 | res.Metrics[prefix+"ns/op"] = res.RunTime
63 | res.Metrics[prefix+"user+sys-ns/op"] = cpuTime(usage) / N
64 | res.Metrics[prefix+"peak-RSS-bytes"] = uint64(usage.Maxrss) * rssMultiplier
65 | return out.String(), nil
66 | }
67 |
68 | func cpuTime(usage *unix.Rusage) uint64 {
69 | return uint64(usage.Utime.Sec)*1e9 + uint64(usage.Utime.Usec*1e3) +
70 | uint64(usage.Stime.Sec)*1e9 + uint64(usage.Stime.Usec)*1e3
71 | }
72 |
73 | func fromStdUsage(su *syscall.Rusage) *unix.Rusage {
74 | return &unix.Rusage{
75 | Utime: unix.Timeval{Sec: su.Utime.Sec, Usec: su.Utime.Usec},
76 | Stime: unix.Timeval{Sec: su.Stime.Sec, Usec: su.Stime.Usec},
77 | Maxrss: su.Maxrss,
78 | Ixrss: su.Ixrss,
79 | Idrss: su.Idrss,
80 | Isrss: su.Isrss,
81 | Minflt: su.Minflt,
82 | Majflt: su.Majflt,
83 | Nswap: su.Nswap,
84 | Inblock: su.Inblock,
85 | Oublock: su.Oublock,
86 | Msgsnd: su.Msgsnd,
87 | Msgrcv: su.Msgrcv,
88 | Nsignals: su.Nsignals,
89 | Nvcsw: su.Nvcsw,
90 | Nivcsw: su.Nivcsw,
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/sweet/benchmarks/bleve-index/main.go:
--------------------------------------------------------------------------------
1 | // Copyright 2021 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | //go:build !aix && !plan9 && !wasm
6 |
7 | package main
8 |
9 | import (
10 | "compress/bzip2"
11 | "flag"
12 | "fmt"
13 | "io"
14 | "os"
15 |
16 | "golang.org/x/benchmarks/sweet/benchmarks/internal/driver"
17 | blevebench "golang.org/x/benchmarks/third_party/bleve-bench"
18 |
19 | "github.com/blevesearch/bleve"
20 | _ "github.com/blevesearch/bleve/analysis/analyzer/keyword"
21 | wikiparse "github.com/dustin/go-wikiparse"
22 | )
23 |
24 | var (
25 | batchSize int
26 | documents int
27 | )
28 |
29 | func init() {
30 | driver.SetFlags(flag.CommandLine)
31 | flag.IntVar(&batchSize, "batch-size", 256, "number of index requests to batch together")
32 | flag.IntVar(&documents, "documents", 1000, "number of documents to index")
33 | }
34 |
35 | func parseFlags() error {
36 | flag.Parse()
37 | if flag.NArg() != 1 {
38 | return fmt.Errorf("expected wiki dump as input")
39 | }
40 | return nil
41 | }
42 |
43 | func run(wikidump string) error {
44 | f, err := os.Open(wikidump)
45 | if err != nil {
46 | return err
47 | }
48 | defer f.Close()
49 |
50 | z := bzip2.NewReader(f)
51 |
52 | parser, err := wikiparse.NewParser(z)
53 | if err != nil {
54 | return err
55 | }
56 |
57 | articles := make([]blevebench.Article, 0, documents)
58 | for d := 0; d < documents; d++ {
59 | p, err := parser.Next()
60 | if err == io.EOF {
61 | break
62 | } else if err != nil {
63 | return err
64 | }
65 | if len(p.Revisions) == 0 {
66 | continue
67 | }
68 | articles = append(articles, blevebench.Article{
69 | Title: p.Title,
70 | Text: p.Revisions[0].Text,
71 | })
72 | }
73 |
74 | mapping := blevebench.ArticleMapping()
75 | name := fmt.Sprintf("BleveIndexBatch%d", batchSize)
76 | return driver.RunBenchmark(name, func(d *driver.B) error {
77 | index, err := bleve.NewMemOnly(mapping)
78 | if err != nil {
79 | return err
80 | }
81 | b := index.NewBatch()
82 | for _, a := range articles {
83 | b.Index(a.Title, a)
84 | if b.Size() >= batchSize {
85 | if err := index.Batch(b); err != nil {
86 | return err
87 | }
88 | b = index.NewBatch()
89 | }
90 | }
91 | if b.Size() != 0 {
92 | if err := index.Batch(b); err != nil {
93 | return err
94 | }
95 | }
96 | d.StopTimer()
97 | return index.Close()
98 | }, driver.InProcessMeasurementOptions...)
99 | }
100 |
101 | func main() {
102 | if err := parseFlags(); err != nil {
103 | fmt.Fprintln(os.Stderr, err)
104 | os.Exit(1)
105 | }
106 | if err := run(flag.Arg(0)); err != nil {
107 | fmt.Fprintln(os.Stderr, err)
108 | os.Exit(1)
109 | }
110 | }
111 |
--------------------------------------------------------------------------------
/sweet/benchmarks/gopher-lua/main.go:
--------------------------------------------------------------------------------
1 | // Copyright 2021 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | //go:build !plan9
6 |
7 | package main
8 |
9 | import (
10 | "bufio"
11 | "flag"
12 | "fmt"
13 | "os"
14 | "strings"
15 |
16 | "golang.org/x/benchmarks/sweet/benchmarks/internal/driver"
17 |
18 | lua "github.com/yuin/gopher-lua"
19 | )
20 |
21 | var short bool
22 |
23 | func init() {
24 | flag.BoolVar(&short, "short", false, "whether to run a short version of this benchmark")
25 | }
26 |
27 | func parseFlags() error {
28 | flag.Parse()
29 | if flag.NArg() != 2 {
30 | return fmt.Errorf("expected lua program and input for it")
31 | }
32 | return nil
33 | }
34 |
35 | func parseInput(inputfile string) (string, error) {
36 | f, err := os.Open(inputfile)
37 | if err != nil {
38 | return "", err
39 | }
40 | defer f.Close()
41 | var builder strings.Builder
42 | scanner := bufio.NewScanner(f)
43 | for scanner.Scan() {
44 | _, err := builder.Write(scanner.Bytes())
45 | if err != nil {
46 | return "", err
47 | }
48 | }
49 | return builder.String(), nil
50 | }
51 |
52 | func doBenchmark(s *lua.LState, input lua.LString) error {
53 | freq := lua.P{
54 | Fn: s.GetGlobal("frequency"),
55 | NRet: 0,
56 | Protect: true,
57 | }
58 | count := lua.P{
59 | Fn: s.GetGlobal("count"),
60 | NRet: 0,
61 | Protect: true,
62 | }
63 | if err := s.CallByParam(freq, input, lua.LNumber(1)); err != nil {
64 | return err
65 | }
66 | if short {
67 | return nil
68 | }
69 | if err := s.CallByParam(freq, input, lua.LNumber(2)); err != nil {
70 | return err
71 | }
72 | if err := s.CallByParam(count, input, lua.LString("GGT")); err != nil {
73 | return err
74 | }
75 | if err := s.CallByParam(count, input, lua.LString("GGTA")); err != nil {
76 | return err
77 | }
78 | if err := s.CallByParam(count, input, lua.LString("GGTATT")); err != nil {
79 | return err
80 | }
81 | return nil
82 | }
83 |
84 | func run(luafile, inputfile string) error {
85 | s := lua.NewState()
86 | defer s.Close()
87 | if err := s.DoFile(luafile); err != nil {
88 | return err
89 | }
90 | input, err := parseInput(inputfile)
91 | if err != nil {
92 | return err
93 | }
94 | return driver.RunBenchmark("GopherLuaKNucleotide", func(_ *driver.B) error {
95 | return doBenchmark(s, lua.LString(input))
96 | }, driver.InProcessMeasurementOptions...)
97 | }
98 |
99 | func main() {
100 | driver.SetFlags(flag.CommandLine)
101 | if err := parseFlags(); err != nil {
102 | fmt.Fprintln(os.Stderr, err)
103 | os.Exit(1)
104 | }
105 | if err := run(flag.Arg(0), flag.Arg(1)); err != nil {
106 | fmt.Fprintln(os.Stderr, err)
107 | os.Exit(1)
108 | }
109 | }
110 |
--------------------------------------------------------------------------------
/cmd/bent/scripts/cmpjob.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash -x
2 |
3 | if [ $# -lt 2 ] ; then
4 | echo cmpjob.sh "" "" "bent-options"
5 | exit 1
6 | fi
7 |
8 | if [ ${1:0:1} = "-" ] ; then
9 | echo "First parameter should be a git tag or branch"
10 | exit 1
11 | fi
12 |
13 | if [ ${2:0:1} = "-" ] ; then
14 | echo "Second parameter should be a git tag or branch"
15 | exit 1
16 | fi
17 |
18 | oldtag="$1"
19 | shift
20 |
21 | newtag="$1"
22 | shift
23 |
24 | ROOT=`pwd`
25 | export ROOT oldtag newtag
26 |
27 | # perflock is not always available
28 | PERFLOCK=`which perflock`
29 |
30 | # N is number of benchmarks, B is number of builds
31 | # Can override these with -N= and -a= on command line.
32 | N=15
33 | B=1
34 |
35 | # Adjust N, B, define NUMACTL, set GOMAXPROCS, as necessary.
36 | if [ -e ./localfix ] ; then
37 | . ./localfix
38 | fi
39 |
40 | REPO="https://go.googlesource.com/go"
41 |
42 | cd "${ROOT}"
43 |
44 | if [ -e go-old ] ; then
45 | rm -rf go-old
46 | fi
47 |
48 | git clone "${REPO}" go-old
49 | if [ "$?" != "0" ] ; then
50 | echo git clone "${REPO}" go-old FAILED
51 | exit 1
52 | fi
53 | cd go-old/src
54 | git fetch "${REPO}" "${oldtag}"
55 | git checkout "${oldtag}"
56 | if [ $? != 0 ] ; then
57 | echo git checkout "${oldtag}" failed
58 | exit 1
59 | fi
60 | ./make.bash
61 | if [ $? != 0 ] ; then
62 | echo BASE make.bash FAILED
63 | exit 1
64 | fi
65 |
66 | cd "${ROOT}"
67 |
68 | if [ -e go-new ] ; then
69 | rm -rf go-new
70 | fi
71 | git clone "${REPO}" go-new
72 | if [ $? != 0 ] ; then
73 | echo git clone go-new failed
74 | exit 1
75 | fi
76 | cd go-new/src
77 | git fetch "${REPO}" "${newtag}"
78 | git checkout "${newtag}"
79 | if [ $? != 0 ] ; then
80 | echo git checkout "${newtag}" failed
81 | exit 1
82 | fi
83 | ./make.bash
84 | if [ $? != 0 ] ; then
85 | echo make.bash failed
86 | exit 1
87 | fi
88 |
89 | cd "${ROOT}"
90 | GOARCH="${BENTARCH}" ${NUMACTL} ${PERFLOCK} bent -v -N=${N} -a=${B} -L=bentjobs.log -C=configurations-cmpjob.toml "$@"
91 | RUN=`tail -1 bentjobs.log | awk -c '{print $1}'`
92 |
93 | cd bench
94 | STAMP="stamp-$$"
95 | export STAMP
96 | echo "suite: bent-cmp-branch" >> "${STAMP}"
97 | echo "bentstamp: ${RUN}" >> "${STAMP}"
98 | echo "oldtag: ${oldtag}" >> "${STAMP}"
99 | echo "newtag: ${newtag}" >> "${STAMP}"
100 |
101 | oldlog="old-${oldtag}"
102 | newlog="new-${newtag}"
103 |
104 | cat "${RUN}.Old.build" > "${oldlog}"
105 | cat "${RUN}.New.build" > "${newlog}"
106 | egrep '^(Benchmark|[-_a-zA-Z0-9]+:)' "${RUN}.Old.stdout" >> "${oldlog}"
107 | egrep '^(Benchmark|[-_a-zA-Z0-9]+:)' "${RUN}.New.stdout" >> "${newlog}"
108 | cat "${RUN}.Old.{benchsize,benchdwarf}" >> "${oldlog}"
109 | cat "${RUN}.New.{benchsize,benchdwarf}" >> "${newlog}"
110 | benchsave -header "${STAMP}" "${oldlog}" "${newlog}"
111 | rm "${STAMP}"
112 |
--------------------------------------------------------------------------------
/cmd/bent/scripts/benchsize:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | tmp=tmp-bench-size-$$
4 |
5 | if [ `uname` = "Darwin" ] ; then
6 | # e.g., `total 20986192`
7 | totalawk='/^total/ {print $2}'
8 | # e.g., ` Section __text: 1445477`
9 | otherawk='$2 ~ "__.?%s:" {tot += $3} END {print tot}'
10 | size -m "$1" > $tmp
11 | wposix=
12 | else
13 | x=`which gsize`
14 | # e.g., `Total 3879861`
15 | totalawk='$1 == "Total" {print $2}'
16 | # e.g., `.text 1269331 4207296`
17 | # Field 2 is size, field 3 is address.
18 | otherawk='$1 ~ ".%s" {tot += $2} END {print tot}'
19 | if [ "x$x" = "x" ] ; then
20 | size -A "$1" > $tmp
21 | else
22 | "$x" -A "$1" > $tmp
23 | fi
24 | wposix="-Wposix"
25 | fi
26 |
27 | # $1: size output file
28 | # $2: section name (without leading .)
29 | function find_section() {
30 | cmd="$(printf "${otherawk}" $2)"
31 | out=$(awk ${wposix} "${cmd}" < $1)
32 | if [[ "${out}" == "" ]]; then
33 | echo 0
34 | else
35 | echo ${out}
36 | fi
37 | }
38 |
39 |
40 | # note total is different
41 | total=$(awk ${wposix} "${totalawk}" < ${tmp})
42 |
43 | text=$(find_section "${tmp}" "text")
44 | gopclntab=$(find_section "${tmp}" "gopclntab")
45 | rodata=$(find_section "${tmp}" "rodata")
46 | data=$(find_section "${tmp}" "data")
47 |
48 | debug_info=$(find_section "${tmp}" "debug_info")
49 | debug_loc=$(find_section "${tmp}" "debug_loc")
50 | debug_line=$(find_section "${tmp}" "debug_line")
51 | debug_ranges=$(find_section "${tmp}" "debug_ranges")
52 | debug_frame=$(find_section "${tmp}" "debug_frame")
53 | debug_abbrev=$(find_section "${tmp}" "debug_abbrev")
54 | debug_pubname=$(find_section "${tmp}" "debug_pubname")
55 | debug_pubtype=$(find_section "${tmp}" "debug_pubtype")
56 |
57 | echo "goos: $GOOS"
58 | echo "goarch: $GOARCH"
59 | echo "pkg:" # Erase any inherited pkg if files are concatenated
60 |
61 | if echo $total | egrep -q '[0-9]+' ; then
62 | echo Unit total-bytes assume=exact
63 | echo "Benchmark${2}" 1 ${total} total-bytes
64 | fi
65 |
66 | if echo $text | egrep -q '[0-9]+' ; then
67 | echo Unit text-bytes assume=exact
68 | echo "Benchmark${2}" 1 ${text} text-bytes
69 | fi
70 |
71 | if echo $data | egrep -q '[0-9]+' ; then
72 | echo Unit data-bytes assume=exact
73 | echo "Benchmark${2}" 1 ${data} data-bytes
74 | fi
75 |
76 | if echo $rodata | egrep -q '[0-9]+' ; then
77 | echo Unit rodata-bytes assume=exact
78 | echo "Benchmark${2}" 1 ${rodata} rodata-bytes
79 | fi
80 |
81 | if echo $gopclntab | egrep -q '[0-9]+' ; then
82 | echo Unit pclntab-bytes assume=exact
83 | echo "Benchmark${2}" 1 ${gopclntab} pclntab-bytes
84 | fi
85 |
86 | debug=`expr ${debug_info} + ${debug_loc} + ${debug_line} + ${debug_ranges} + ${debug_frame} + ${debug_abbrev} + ${debug_pubname} + ${debug_pubtype}`
87 |
88 | if echo $debug | egrep -q '[0-9]+' ; then
89 | echo Unit debug-bytes assume=exact
90 | echo "Benchmark${2}" 1 ${debug} debug-bytes
91 | fi
92 |
93 | rm $tmp
94 |
--------------------------------------------------------------------------------
/sweet/common/log/log.go:
--------------------------------------------------------------------------------
1 | // Copyright 2021 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package log
6 |
7 | import (
8 | "fmt"
9 | "log"
10 | "os"
11 | "os/exec"
12 | "path/filepath"
13 | "strings"
14 |
15 | shellquote "github.com/kballard/go-shellquote"
16 | )
17 |
18 | var (
19 | cmdLog, actLog *log.Logger
20 | cmdOn, actOn = false, false
21 | envMap map[string]string
22 | )
23 |
24 | func init() {
25 | cmdLog = log.New(os.Stdout, "[shell] ", 0)
26 | actLog = log.New(os.Stderr, "[sweet] ", 0)
27 | envMap = makeEnvironMap()
28 | }
29 |
30 | func makeEnvironMap() map[string]string {
31 | env := os.Environ()
32 | envmap := make(map[string]string)
33 | for _, e := range env {
34 | s := strings.SplitN(e, "=", 2)
35 | if len(s) != 2 {
36 | continue
37 | }
38 | envmap[s[0]] = s[1]
39 | }
40 | return envmap
41 | }
42 |
43 | func SetCommandTrace(on bool) {
44 | cmdOn = on
45 | }
46 |
47 | func SetActivityLog(on bool) {
48 | actOn = on
49 | }
50 |
51 | func filterAndQuoteEnviron(env []string) []string {
52 | fenv := make([]string, 0, len(env))
53 | for _, e := range env {
54 | s := strings.SplitN(e, "=", 2)
55 | if len(s) != 2 {
56 | continue
57 | }
58 | if v, ok := envMap[s[0]]; ok && v == s[1] {
59 | continue
60 | }
61 | fenv = append(fenv, fmt.Sprintf("%s=%s", s[0], shellquote.Join(s[1])))
62 | }
63 | return fenv
64 | }
65 |
66 | func TraceCommand(cmd *exec.Cmd, background bool) {
67 | if !cmdOn {
68 | return
69 | }
70 | senv := ""
71 | if len(cmd.Env) != 0 {
72 | senv = strings.Join(filterAndQuoteEnviron(cmd.Env), " ")
73 | }
74 | if cmd.Dir != "" {
75 | cmdLog.Printf("pushd %s", cmd.Dir)
76 | }
77 | sbg := ""
78 | if background {
79 | sbg = " &"
80 | }
81 | sarg := shellquote.Join(cmd.Args...)
82 | if senv != "" {
83 | cmdLog.Printf("%s %s%s", senv, sarg, sbg)
84 | } else {
85 | cmdLog.Printf("%s%s", sarg, sbg)
86 | }
87 | if cmd.Dir != "" {
88 | cmdLog.Printf("popd")
89 | }
90 | }
91 |
92 | func TraceKill(cmd *exec.Cmd) {
93 | if !cmdOn {
94 | return
95 | }
96 | cmdLog.Printf("killall -SIGINT %s", filepath.Base(cmd.Path))
97 | }
98 |
99 | func CommandPrintf(format string, args ...interface{}) {
100 | if !cmdOn {
101 | return
102 | }
103 | cmdLog.Printf(format, args...)
104 | }
105 |
106 | func Printf(format string, args ...interface{}) {
107 | if !actOn {
108 | return
109 | }
110 | actLog.Printf(format, args...)
111 | }
112 |
113 | func Print(args ...interface{}) {
114 | if !actOn {
115 | return
116 | }
117 | actLog.Print(args...)
118 | }
119 |
120 | func Error(err error) {
121 | actLog.Printf("error: %v", err)
122 | if e, ok := err.(*exec.ExitError); ok {
123 | actLog.Printf("output:\n%s", string(e.Stderr))
124 | }
125 | }
126 |
--------------------------------------------------------------------------------
/http/http.go:
--------------------------------------------------------------------------------
1 | // Copyright 2014 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // HTTP is a benchmark that examines client/server http performance.
6 | package main
7 |
8 | import (
9 | "fmt"
10 | "io"
11 | "log"
12 | "net"
13 | "net/http"
14 | "os"
15 | "runtime"
16 | "time"
17 |
18 | "golang.org/x/benchmarks/driver"
19 | )
20 |
21 | func main() {
22 | driver.Main("HTTP", benchmark)
23 | }
24 |
25 | func benchmark() driver.Result {
26 | return driver.Benchmark(benchmarkHTTPImpl)
27 | }
28 |
29 | const procs = 4
30 |
31 | func benchmarkHTTPImpl(N uint64) {
32 | driver.Parallel(N, procs, func() {
33 | t0 := time.Now()
34 | makeOneRequest()
35 | driver.LatencyNote(t0)
36 | })
37 | }
38 |
39 | func makeOneRequest() bool {
40 | res, err := client.Get(server.Addr)
41 | if err != nil {
42 | // Under heavy load with GOMAXPROCS>>1, it frequently fails
43 | // with transient failures like:
44 | // "dial tcp: cannot assign requested address"
45 | // or:
46 | // "ConnectEx tcp: Only one usage of each socket address
47 | // (protocol/network address/port) is normally permitted".
48 | // So we just log and continue,
49 | // otherwise significant fraction of benchmarks will fail.
50 | log.Printf("Get: %v", err)
51 | return false
52 | }
53 | defer res.Body.Close()
54 | b, err := io.ReadAll(res.Body)
55 | if err != nil {
56 | log.Fatalf("ReadAll: %v", err)
57 | }
58 | if s := string(b); s != "Hello world.\n" {
59 | log.Fatalf("Got body: %q", s)
60 | }
61 | return true
62 | }
63 |
64 | var (
65 | server *http.Server
66 | client *http.Client
67 | )
68 |
69 | func init() {
70 | // These environment variables affect net/http behavior,
71 | // ensure that we get predictable results regardless of environment on the machine.
72 | os.Setenv("HTTP_PROXY", "")
73 | os.Setenv("http_proxy", "")
74 | os.Setenv("NO_PROXY", "")
75 | os.Setenv("no_proxy", "")
76 |
77 | l, err := net.Listen("tcp", "127.0.0.1:0")
78 | if err != nil {
79 | if l, err = net.Listen("tcp6", "[::1]:0"); err != nil {
80 | log.Fatalf("failed to listen: %v", err)
81 | }
82 | }
83 | server = &http.Server{
84 | Addr: "http://" + l.Addr().String(),
85 | ReadTimeout: 10 * time.Second,
86 | WriteTimeout: 10 * time.Second,
87 | MaxHeaderBytes: 1 << 20,
88 | Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
89 | fmt.Fprintf(w, "Hello world.\n")
90 | }),
91 | }
92 | go server.Serve(l)
93 |
94 | client = &http.Client{
95 | Transport: &http.Transport{
96 | // just what default client uses
97 | Proxy: http.ProxyFromEnvironment,
98 | // this leads to more stable numbers
99 | MaxIdleConnsPerHost: procs * runtime.GOMAXPROCS(0),
100 | },
101 | }
102 |
103 | if !makeOneRequest() {
104 | log.Fatalf("server is not listening")
105 | }
106 | }
107 |
--------------------------------------------------------------------------------
/sweet/harnesses/common.go:
--------------------------------------------------------------------------------
1 | // Copyright 2021 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package harnesses
6 |
7 | import (
8 | "bytes"
9 | "fmt"
10 | "os"
11 | "os/exec"
12 | "path/filepath"
13 |
14 | "golang.org/x/benchmarks/sweet/common/fileutil"
15 | "golang.org/x/benchmarks/sweet/common/log"
16 | )
17 |
18 | func gitShallowClone(dir, url, ref string) error {
19 | // Git 2.46+ has a global --no-advice flag, but that's extremely recent as of this writing.
20 | cmd := exec.Command("git", "-c", "advice.detachedHead=false", "clone", "--depth", "1", "-b", ref, url, dir)
21 | log.TraceCommand(cmd, false)
22 | var buf bytes.Buffer
23 | cmd.Stderr = &buf
24 | if _, err := cmd.Output(); err != nil {
25 | return fmt.Errorf("git shallow clone: %v: stderr:\n%s", err, &buf)
26 | }
27 | return nil
28 | }
29 |
30 | func gitRecursiveCloneToCommit(dir, url, branch, hash string) error {
31 | cloneCmd := exec.Command("git", "clone", "--recursive", "--shallow-submodules", "-b", branch, url, dir)
32 | log.TraceCommand(cloneCmd, false)
33 | var buf bytes.Buffer
34 | cloneCmd.Stderr = &buf
35 | if _, err := cloneCmd.Output(); err != nil {
36 | return fmt.Errorf("git recursive clone: %v: stderr:\n%s", err, &buf)
37 | }
38 | buf.Reset()
39 | checkoutCmd := exec.Command("git", "-C", dir, "-c", "advice.detachedHead=false", "checkout", hash)
40 | log.TraceCommand(checkoutCmd, false)
41 | checkoutCmd.Stderr = &buf
42 | if _, err := checkoutCmd.Output(); err != nil {
43 | return fmt.Errorf("git checkout: %v: stderr:\n%s", err, &buf)
44 | }
45 | return nil
46 | }
47 |
48 | func gitCloneToCommit(dir, url, branch, hash string) error {
49 | cloneCmd := exec.Command("git", "clone", "-b", branch, url, dir)
50 | log.TraceCommand(cloneCmd, false)
51 | var buf bytes.Buffer
52 | cloneCmd.Stderr = &buf
53 | if _, err := cloneCmd.Output(); err != nil {
54 | return fmt.Errorf("git recursive clone: %v: stderr:\n%s", err, &buf)
55 | }
56 | buf.Reset()
57 | checkoutCmd := exec.Command("git", "-C", dir, "-c", "advice.detachedHead=false", "checkout", hash)
58 | log.TraceCommand(checkoutCmd, false)
59 | checkoutCmd.Stderr = &buf
60 | if _, err := checkoutCmd.Output(); err != nil {
61 | return fmt.Errorf("git checkout: %v: stderr:\n%s", err, &buf)
62 | }
63 | return nil
64 | }
65 |
66 | func copyFile(dst, src string) error {
67 | log.CommandPrintf("cp %s %s", src, dst)
68 | return fileutil.CopyFile(dst, src, nil, nil)
69 | }
70 |
71 | func makeWriteable(dir string) error {
72 | log.CommandPrintf("chmod -R a+w %s", dir)
73 | return filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
74 | if err != nil {
75 | return err
76 | }
77 | if info.Mode()&0222 == 0222 {
78 | return nil
79 | }
80 | return os.Chmod(path, info.Mode()|0222)
81 | })
82 | }
83 |
84 | func symlink(dst, src string) error {
85 | log.CommandPrintf("ln -s %s %s", src, dst)
86 | return os.Symlink(src, dst)
87 | }
88 |
--------------------------------------------------------------------------------
/sweet/harnesses/tile38.go:
--------------------------------------------------------------------------------
1 | // Copyright 2021 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package harnesses
6 |
7 | import (
8 | "os/exec"
9 | "path/filepath"
10 |
11 | "golang.org/x/benchmarks/sweet/common"
12 | "golang.org/x/benchmarks/sweet/common/log"
13 | )
14 |
15 | const (
16 | server = "tile38-server"
17 | )
18 |
19 | type Tile38 struct{}
20 |
21 | func (h Tile38) CheckPrerequisites() error {
22 | return nil
23 | }
24 |
25 | func (h Tile38) Get(gcfg *common.GetConfig) error {
26 | return gitShallowClone(
27 | gcfg.SrcDir,
28 | "https://github.com/tidwall/tile38",
29 | "1.29.1",
30 | )
31 | }
32 |
33 | func (h Tile38) Build(cfg *common.Config, bcfg *common.BuildConfig) error {
34 | env := cfg.BuildEnv.Env
35 |
36 | // Add the Go tool to PATH, since tile38's Makefile doesn't provide enough
37 | // visibility into how tile38 is built to allow us to pass this information
38 | // directly. Also set the GOROOT explicitly because it might have propagated
39 | // differently from the environment.
40 | env = env.Prefix("PATH", filepath.Join(cfg.GoRoot, "bin")+":")
41 | env = env.MustSet("GOROOT=" + cfg.GoRoot)
42 |
43 | cmd := exec.Command("make", "-C", bcfg.SrcDir)
44 | cmd.Env = env.Collapse()
45 | log.TraceCommand(cmd, false)
46 | // Call Output here to get an *ExitError with a populated Stderr field.
47 | if _, err := cmd.Output(); err != nil {
48 | return err
49 | }
50 | // Note that no matter what we do, the build script insists on putting the
51 | // binaries into the source directory, so copy the one we care about into
52 | // BinDir.
53 | if err := copyFile(filepath.Join(bcfg.BinDir, server), filepath.Join(bcfg.SrcDir, server)); err != nil {
54 | return err
55 | }
56 | return cfg.GoTool(bcfg.BuildLog).BuildPath(bcfg.BenchDir, filepath.Join(bcfg.BinDir, "tile38-bench"))
57 | }
58 |
59 | func (h Tile38) Run(cfg *common.Config, rcfg *common.RunConfig) error {
60 | var dataPath string
61 | if rcfg.Short {
62 | // Don't load the real data for short mode. It takes a long time.
63 | dataPath = filepath.Join(rcfg.TmpDir, "data-empty-fake")
64 | } else {
65 | // Make sure all the data passed to the server is writable.
66 | // The server needs to be able to open its persistent storage as read-write.
67 | dataPath = filepath.Join(rcfg.AssetsDir, "data")
68 | if err := makeWriteable(dataPath); err != nil {
69 | return err
70 | }
71 | }
72 | args := append(rcfg.Args, []string{
73 | "-host", "127.0.0.1",
74 | "-port", "9851",
75 | "-server", filepath.Join(rcfg.BinDir, server),
76 | "-data", dataPath,
77 | "-tmp", rcfg.TmpDir,
78 | }...)
79 | if rcfg.Short {
80 | args = append(args, "-short")
81 | }
82 | cmd := exec.Command(
83 | filepath.Join(rcfg.BinDir, "tile38-bench"),
84 | args...,
85 | )
86 | cmd.Env = cfg.ExecEnv.Collapse()
87 | cmd.Stdout = rcfg.Results
88 | cmd.Stderr = rcfg.Log
89 | log.TraceCommand(cmd, false)
90 | return cmd.Run()
91 | }
92 |
--------------------------------------------------------------------------------
/sweet/source-assets/gvisor/http/server.go:
--------------------------------------------------------------------------------
1 | // Copyright 2021 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package main
6 |
7 | import (
8 | "context"
9 | "flag"
10 | "fmt"
11 | "log"
12 | "net/http"
13 | "os"
14 | "os/signal"
15 | "path/filepath"
16 | "runtime"
17 | "text/template"
18 | "time"
19 | )
20 |
21 | var (
22 | host string
23 | port int
24 | procs int
25 | assetsRoot string
26 | )
27 |
28 | func init() {
29 | flag.StringVar(&host, "host", "localhost", "host to serve on")
30 | flag.IntVar(&port, "port", 8081, "port to serve on")
31 | flag.IntVar(&procs, "procs", runtime.GOMAXPROCS(-1), "how many processors to use")
32 | flag.StringVar(&assetsRoot, "assets", "./assets", "directory to serve assets from")
33 | }
34 |
35 | var frontPage = template.Must(template.New("front").Parse(`
36 | {{- range . -}}
37 | {{.}}
38 | {{end -}}
39 | `))
40 |
41 | func main() {
42 | flag.Parse()
43 | runtime.GOMAXPROCS(procs)
44 |
45 | var images []string
46 | filepath.Walk(assetsRoot, func(path string, info os.FileInfo, err error) error {
47 | if err != nil {
48 | log.Printf("warning: failed to walk %s: %v", path, err)
49 | return nil
50 | }
51 | if info.IsDir() {
52 | // Ignore directories.
53 | return nil
54 | }
55 | relPath, _ := filepath.Rel(assetsRoot, path)
56 | switch filepath.Ext(path) {
57 | case ".jpg", ".png", ".gif":
58 | images = append(images, relPath)
59 | default:
60 | }
61 | return nil
62 | })
63 | for i, img := range images {
64 | images[i] = filepath.Join("/static", img)
65 | log.Printf("Image: %s", images[i])
66 | }
67 |
68 | ctx := context.Background()
69 | ctx, cancel := signal.NotifyContext(ctx, os.Interrupt)
70 | defer cancel()
71 |
72 | // Set up a done channel.
73 | http.Handle("/static/", http.FileServer(http.Dir(assetsRoot)))
74 | http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
75 | if r.URL.Path != "/" {
76 | http.NotFound(w, r)
77 | return
78 | }
79 | if err := frontPage.Execute(w, images); err != nil {
80 | http.Error(w, fmt.Sprintf("Internal server error: %s", err.Error()), 500)
81 | return
82 | }
83 | })
84 |
85 | server := &http.Server{Addr: fmt.Sprintf("%s:%d", host, port), Handler: http.DefaultServeMux}
86 | go func() {
87 | err := server.ListenAndServe()
88 | if err != nil && err != http.ErrServerClosed {
89 | log.Fatalf("Server error listening/serving: %s", err)
90 | }
91 | }()
92 |
93 | // Wait for a signal to stop.
94 | <-ctx.Done()
95 |
96 | // Shut down the server cleanly.
97 | exitCtx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
98 | defer cancel()
99 |
100 | if err := server.Shutdown(exitCtx); err != nil {
101 | log.Printf("Clean shutdown failed: %v", err)
102 | return
103 | }
104 | log.Print("Shut down successfully. Goodbye!")
105 | }
106 |
--------------------------------------------------------------------------------
/cmd/bent/scripts/cmpcl.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash -x
2 |
3 | # git fetch "https://go.googlesource.com/go" refs/changes/61/196661/3 && git checkout FETCH_HEAD
4 |
5 | if [ $# -lt 1 ] ; then
6 | echo cmpcl.sh "refs/changes///" "bent-options"
7 | exit 1
8 | fi
9 |
10 | if [ ${1:0:1} = "-" ] ; then
11 | echo "First parameter should be a git tag or branch"
12 | exit 1
13 | fi
14 |
15 | cl="$1"
16 | shift
17 |
18 | ROOT=`pwd`
19 | export ROOT cl
20 |
21 | # perflock is not always available
22 | PERFLOCK=`which perflock`
23 |
24 | # N is number of benchmarks.
25 | # Can override thise with -R=
26 | N=15
27 |
28 | # Adjust N, B, define NUMACTL, set GOMAXPROCS, as necessary.
29 | if [ -e ./localfix ] ; then
30 | . ./localfix
31 | fi
32 |
33 | cd "${ROOT}"
34 |
35 | if [ -e go-old ] ; then
36 | rm -rf go-old
37 | fi
38 |
39 | git clone https://go.googlesource.com/go go-old
40 | if [ $? != 0 ] ; then
41 | echo git clone https://go.googlesource.com/go go-old FAILED
42 | exit 1
43 | fi
44 | cd go-old/src
45 | git fetch "https://go.googlesource.com/go" "${cl}"
46 | if [ $? != 0 ] ; then
47 | echo git fetch "https://go.googlesource.com/go" "${cl}" failed
48 | exit 1
49 | fi
50 | git checkout FETCH_HEAD^1
51 | if [ $? != 0 ] ; then
52 | echo git checkout FETCH_HEAD^1 failed
53 | exit 1
54 | fi
55 | ./make.bash
56 | if [ $? != 0 ] ; then
57 | echo BASE make.bash FAILED
58 | exit 1
59 | fi
60 | oldtag=`git log -n 1 --format='%h'`
61 | export oldtag
62 |
63 | cd "${ROOT}"
64 |
65 | if [ -e go-new ] ; then
66 | rm -rf go-new
67 | fi
68 | git clone https://go.googlesource.com/go go-new
69 | if [ $? != 0 ] ; then
70 | echo git clone go-new failed
71 | exit 1
72 | fi
73 | cd go-new/src
74 |
75 | git fetch "https://go.googlesource.com/go" "${cl}"
76 | if [ $? != 0 ] ; then
77 | echo git fetch "https://go.googlesource.com/go" "${cl}" failed
78 | exit 1
79 | fi
80 | git checkout FETCH_HEAD
81 | if [ $? != 0 ] ; then
82 | echo git checkout FETCH_HEAD failed
83 | exit 1
84 | fi
85 |
86 | ./make.bash
87 | if [ $? != 0 ] ; then
88 | echo make.bash failed
89 | exit 1
90 | fi
91 | newtag=`git log -n 1 --format='%h'`
92 | export newtag
93 |
94 | cd "${ROOT}"
95 | GOARCH="${BENTARCH}" ${NUMACTL} ${PERFLOCK} bent -v -R=${N} -L=bentjobs.log -C=configurations-cmpjob.toml "$@"
96 | RUN=`tail -1 bentjobs.log | awk -c '{print $1}'`
97 |
98 | cd bench
99 | STAMP="stamp-$$"
100 | export STAMP
101 | echo "suite: bent-cmp-cl" >> ${STAMP}
102 | echo "bentstamp: ${RUN}" >> "${STAMP}"
103 | echo "oldtag: ${oldtag}" >> "${STAMP}"
104 | echo "newtag: ${newtag}" >> "${STAMP}"
105 |
106 | oldlog="old-${oldtag}"
107 | newlog="new-${newtag}"
108 |
109 | cat "${RUN}.Old.build" > "${oldlog}"
110 | cat "${RUN}.New.build" > "${newlog}"
111 | egrep '^(Benchmark|[-_a-zA-Z0-9]+:)' "${RUN}.Old.stdout" >> "${oldlog}"
112 | egrep '^(Benchmark|[-_a-zA-Z0-9]+:)' "${RUN}.New.stdout" >> "${newlog}"
113 | cat "${RUN}.Old.{benchsize,benchdwarf}" >> "${oldlog}"
114 | cat "${RUN}.New.{benchsize,benchdwarf}" >> "${newlog}"
115 | benchsave -header "${STAMP}" "${oldlog}" "${newlog}"
116 | rm "${STAMP}"
117 |
--------------------------------------------------------------------------------
/sweet/common/gotool.go:
--------------------------------------------------------------------------------
1 | // Copyright 2021 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package common
6 |
7 | import (
8 | "fmt"
9 | "io"
10 | "os"
11 | "os/exec"
12 | "path/filepath"
13 |
14 | "golang.org/x/benchmarks/sweet/common/log"
15 | )
16 |
17 | type Go struct {
18 | Tool string
19 | Env *Env
20 | PassOutput bool
21 | BuildLog io.Writer
22 | }
23 |
24 | func SystemGoTool() (*Go, error) {
25 | tool, err := exec.LookPath("go")
26 | if err != nil {
27 | return nil, fmt.Errorf("looking for system Go: %w", err)
28 | }
29 | return &Go{
30 | Tool: tool,
31 | Env: NewEnvFromEnviron().MustSet("GOROOT=" + filepath.Dir(filepath.Dir(tool))),
32 | }, nil
33 | }
34 |
35 | func (g *Go) Do(dir string, args ...string) error {
36 | cmd := exec.Command(g.Tool, args...)
37 | if dir != "" {
38 | cmd.Dir = dir
39 | }
40 | cmd.Env = g.Env.Collapse()
41 | if g.PassOutput {
42 | cmd.Stdout = os.Stdout
43 | cmd.Stderr = os.Stderr
44 | } else if g.BuildLog != nil {
45 | cmd.Stderr = g.BuildLog
46 | cmd.Stdout = g.BuildLog
47 | }
48 | log.TraceCommand(cmd, false)
49 | if g.PassOutput || g.BuildLog != nil {
50 | return cmd.Run()
51 | }
52 | // Use cmd.Output to get an ExitError with Stderr populated.
53 | _, err := cmd.Output()
54 | if ee, ok := err.(*exec.ExitError); ok {
55 | // ExitError includes stderr, but doesn't inclue it in Error.
56 | // Create a new error that does display stderr.
57 | return fmt.Errorf("%w. stderr:\n%s", err, ee.Stderr)
58 | }
59 | return err
60 | }
61 |
62 | func (g *Go) List(args ...string) ([]byte, error) {
63 | cmd := exec.Command(g.Tool, append([]string{"list"}, args...)...)
64 | cmd.Env = g.Env.Collapse()
65 | log.TraceCommand(cmd, false)
66 | return cmd.Output()
67 | }
68 |
69 | func (g *Go) GOROOT() string {
70 | return filepath.Dir(filepath.Dir(g.Tool))
71 | }
72 |
73 | func (g *Go) BuildPackage(pkg, out string) error {
74 | if pkg[0] == '/' || pkg[0] == '.' {
75 | return fmt.Errorf("path used as package in go build")
76 | }
77 | return g.Do("", "build", "-o", out, pkg)
78 | }
79 |
80 | func (g *Go) Version() (string, error) {
81 | cmd := exec.Command(g.Tool, "version")
82 | cmd.Env = g.Env.Collapse()
83 | log.TraceCommand(cmd, false)
84 | out, err := cmd.Output()
85 | if err != nil {
86 | return "", fmt.Errorf("error running 'go version': %w", err)
87 | }
88 | return string(out), nil
89 | }
90 |
91 | func (g *Go) BuildPath(path, out string, args ...string) error {
92 | if path[0] != '/' && path[0] != '.' {
93 | path = "./" + path
94 | }
95 | cwd, err := os.Getwd()
96 | if err != nil {
97 | return fmt.Errorf("failed to get current working directory: %w", err)
98 | }
99 | defer chdir(cwd)
100 | if err := chdir(path); err != nil {
101 | return fmt.Errorf("failed to enter build directory: %w", err)
102 | }
103 | args = append([]string{"build", "-o", out}, args...)
104 | return g.Do("", args...)
105 | }
106 |
107 | func chdir(path string) error {
108 | log.CommandPrintf("cd %s", path)
109 | return os.Chdir(path)
110 | }
111 |
--------------------------------------------------------------------------------
/cmd/bench/gotest.go:
--------------------------------------------------------------------------------
1 | // Copyright 2021 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package main
6 |
7 | import (
8 | "fmt"
9 | "log"
10 | "path/filepath"
11 | )
12 |
13 | func goTest(tcs []*toolchain, pgo bool) error {
14 | if pgo {
15 | log.Printf("Skipping Go test benchmarks (PGO not supported)")
16 | return nil
17 | }
18 | for _, tc := range tcs {
19 | log.Printf("Running Go test benchmarks for %s", tc.Name)
20 | fmt.Printf("toolchain: %s\n", tc.Name)
21 | err := tc.Do("", "test", "-v", "-run=none", "-short", "-bench=.", "-count=6", "golang.org/x/benchmarks/...")
22 | if err != nil {
23 | return fmt.Errorf("error running gotest with toolchain %s: %w", tc.Name, err)
24 | }
25 | }
26 | return nil
27 | }
28 |
29 | // goTestSubrepo runs subrepo tests for the subrepo x/, where the
30 | // baseline commit is checked out in baselineDir, and the experiment commit is
31 | // checked out in experimentDir.
32 | //
33 | // To run subrepo tests locally, use this incantation:
34 | //
35 | // ./bench -wait=false \
36 | // -repository=tools \
37 | // -subrepo=/path/to/experiment \
38 | // -subrepo-baseline=/path/to/baseline \
39 | // -goroot-baseline=$(go env GOROOT)
40 | func goTestSubrepo(tc *toolchain, subRepo, baselineDir, experimentDir string) error {
41 | // Note: tests must write "toolchain: baseline|experiment" to stdout before
42 | // running benchmarks for the corresponding commit, as this is parsed as a
43 | // benchmark tag.
44 | switch subRepo {
45 | case "tools":
46 | log.Printf("Running sub-repo benchmarks for %s", subRepo)
47 |
48 | // Gopls tests run benchmarks defined in the experimentDir (i.e. the latest
49 | // versions of the benchmarks themselves).
50 | //
51 | // Benchmarks all communicate with a separate gopls process, which can be
52 | // configured via the -gopls_path flag.
53 | //
54 | // By convention, gopls uses -short to define tests that should be run by
55 | // x/benchmarks.
56 | benchmarkDir := filepath.Join(experimentDir, "gopls", "internal", "test", "integration", "bench")
57 |
58 | tests := []struct {
59 | name string // toolchain name
60 | goplsDir string // dir where gopls should be built
61 | }{
62 | {"baseline", filepath.Join(baselineDir, "gopls")},
63 | {"experiment", filepath.Join(experimentDir, "gopls")},
64 | }
65 |
66 | for _, test := range tests {
67 | err := tc.Do(test.goplsDir, "build")
68 | if err != nil {
69 | return fmt.Errorf("error building sub-repo %s with toolchain %s in dir %s: %w", subRepo, tc.Name, test.goplsDir, err)
70 | }
71 |
72 | fmt.Printf("toolchain: %s\n", test.name) // set the toolchain tag
73 |
74 | goplsPath := filepath.Join(test.goplsDir, "gopls")
75 | err = tc.Do(benchmarkDir, "test", "-short", "-bench=.", fmt.Sprintf(`-gopls_path=%s`, goplsPath), "-count=6", "-timeout=180m")
76 | if err != nil {
77 | return fmt.Errorf("error running sub-repo %s benchmark %q with toolchain %s in dir %s: %w", subRepo, test.name, tc.Name, benchmarkDir, err)
78 | }
79 | }
80 |
81 | default:
82 | return fmt.Errorf("unsupported subrepo %s", subRepo)
83 | }
84 |
85 | return nil
86 | }
87 |
--------------------------------------------------------------------------------
/third_party/biogo-examples/krishna/krishna.go:
--------------------------------------------------------------------------------
1 | // Copyright ©2014 The bíogo Authors. All rights reserved.
2 | // Copyright 2021 The Go Authors. All rights reserved.
3 | // Use of this source code is governed by a BSD-style
4 | // license that can be found in the LICENSE file.
5 |
6 | package krishna
7 |
8 | import (
9 | "fmt"
10 | "sync"
11 |
12 | "github.com/biogo/biogo/align/pals"
13 | "github.com/biogo/biogo/align/pals/filter"
14 | "github.com/biogo/biogo/morass"
15 | )
16 |
17 | type Params struct {
18 | TmpChunkSize int
19 | MinHitLen int
20 | MinHitId float64
21 | TubeOffset int
22 | AlignConc bool
23 | TmpConc bool
24 | }
25 |
26 | // Krishna is a pure Go implementation of Edgar and Myers PALS tool.
27 | // This version of krishna is modified from its original form and only
28 | // computes alignment for a sequence against itself.
29 | type Krishna struct {
30 | params Params
31 | target *pals.Packed
32 | pa [2]*pals.PALS
33 | }
34 |
35 | func New(seqPath, tmpDir string, params Params) (*Krishna, error) {
36 | target, err := packSequence(seqPath)
37 | if err != nil {
38 | return nil, err
39 | }
40 | if target.Len() == 0 {
41 | return nil, fmt.Errorf("target sequence is zero length")
42 | }
43 | // Allocate morass before since these can be somewhat large
44 | // and single large allocations tend to be noisy.
45 | m1, err := morass.New(filter.Hit{}, "krishna_", tmpDir, params.TmpChunkSize, params.TmpConc)
46 | if err != nil {
47 | return nil, err
48 | }
49 | m2, err := morass.New(filter.Hit{}, "krishna_", tmpDir, params.TmpChunkSize, params.TmpConc)
50 | if err != nil {
51 | return nil, err
52 | }
53 | pa := [2]*pals.PALS{
54 | pals.New(target.Seq, target.Seq, true, m1, params.TubeOffset, nil, nil),
55 | pals.New(target.Seq, target.Seq, true, m2, params.TubeOffset, nil, nil),
56 | }
57 | return &Krishna{params, target, pa}, nil
58 | }
59 |
60 | // Returns a cleanup function, and an error. The cleanup function should be
61 | // called before program exit, if not nil.
62 | func (k *Krishna) Run(writer *pals.Writer) error {
63 | if err := k.pa[0].Optimise(k.params.MinHitLen, k.params.MinHitId); err != nil {
64 | return err
65 | }
66 | if err := k.pa[0].BuildIndex(); err != nil {
67 | return err
68 | }
69 | k.pa[1].Share(k.pa[0])
70 |
71 | var wg sync.WaitGroup
72 | errs := make([]error, 2)
73 | for i, comp := range [...]bool{false, true} {
74 | wg.Add(1)
75 | go func(i int, p *pals.PALS, comp bool) {
76 | defer wg.Done()
77 | hits, err := p.Align(comp)
78 | if err != nil {
79 | errs[i] = err
80 | return
81 | }
82 | _, err = writeDPHits(writer, k.target, k.target, hits, comp)
83 | if err != nil {
84 | errs[i] = err
85 | return
86 | }
87 | }(i, k.pa[i], comp)
88 | if !k.params.AlignConc {
89 | // Block until it's done if we don't want to run
90 | // the alignment processing concurrently.
91 | wg.Wait()
92 | }
93 | }
94 | wg.Wait()
95 |
96 | for _, err := range errs {
97 | if err != nil {
98 | return err
99 | }
100 | }
101 | return nil
102 | }
103 |
104 | func (k *Krishna) CleanUp() {
105 | for _, p := range k.pa {
106 | p.CleanUp()
107 | }
108 | }
109 |
--------------------------------------------------------------------------------
/garbage/garbage.go:
--------------------------------------------------------------------------------
1 | // Copyright 2014 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | // Garbage is a benchmark that stresses garbage collector.
6 | // It repeatedly parses net/http package with go/parser and then discards results.
7 | package main
8 |
9 | // The source of net/http was captured at git tag go1.5.2 by
10 | //go:generate sh -c "(echo 'package garbage'; echo 'var src = `'; bundle net/http http '' | sed 's/`/`+\"`\"+`/g'; echo '`') > nethttp.go"
11 |
12 | import (
13 | "fmt"
14 | "go/ast"
15 | "go/parser"
16 | "go/token"
17 | "runtime"
18 | "sync"
19 | "sync/atomic"
20 |
21 | "golang.org/x/benchmarks/driver"
22 | )
23 |
24 | func main() {
25 | driver.Main("Garbage", benchmark)
26 | }
27 |
28 | type ParsedPackage *ast.File
29 |
30 | var (
31 | parsed []ParsedPackage
32 | )
33 |
34 | func benchmark() driver.Result {
35 | if parsed == nil {
36 | mem := packageMemConsumption()
37 | avail := (driver.BenchMem() << 20) * 4 / 5 // 4/5 to account for non-heap memory
38 | npkg := avail / mem / 2 // 2 to account for GOGC=100
39 | parsed = make([]ParsedPackage, npkg)
40 | for n := 0; n < 2; n++ { // warmup GC
41 | for i := range parsed {
42 | parsed[i] = parsePackage()
43 | }
44 | }
45 | fmt.Printf("consumption=%vKB npkg=%d\n", mem>>10, npkg)
46 | }
47 | return driver.Benchmark(benchmarkN)
48 | }
49 |
50 | func benchmarkN(N uint64) {
51 | P := runtime.GOMAXPROCS(0)
52 | // Create G goroutines, but only 2*P of them parse at the same time.
53 | G := 1024
54 | gate := make(chan bool, 2*P)
55 | var mu sync.Mutex
56 | var wg sync.WaitGroup
57 | wg.Add(G)
58 | remain := int64(N)
59 | pos := 0
60 | for g := 0; g < G; g++ {
61 | go func() {
62 | defer wg.Done()
63 | for atomic.AddInt64(&remain, -1) >= 0 {
64 | gate <- true
65 | p := parsePackage()
66 | mu.Lock()
67 | // Overwrite only half of the array,
68 | // the other part represents "old" generation.
69 | parsed[pos%(len(parsed)/2)] = p
70 | pos++
71 | mu.Unlock()
72 | <-gate
73 | }
74 | }()
75 | }
76 | wg.Wait()
77 | }
78 |
79 | // packageMemConsumption returns memory consumption of a single parsed package.
80 | func packageMemConsumption() int {
81 | // One GC does not give precise results,
82 | // because concurrent sweep may be still in progress.
83 | runtime.GC()
84 | runtime.GC()
85 | ms0 := new(runtime.MemStats)
86 | runtime.ReadMemStats(ms0)
87 | const N = 10
88 | var parsed [N]ParsedPackage
89 | for i := range parsed {
90 | parsed[i] = parsePackage()
91 | }
92 | runtime.GC()
93 | runtime.GC()
94 | // Keep it alive.
95 | if parsed[0] == nil {
96 | fmt.Println(&parsed)
97 | }
98 | ms1 := new(runtime.MemStats)
99 | runtime.ReadMemStats(ms1)
100 | mem := int(ms1.Alloc-ms0.Alloc) / N
101 | if mem < 1<<16 {
102 | mem = 1 << 16
103 | }
104 | return mem
105 | }
106 |
107 | // parsePackage parses and returns net/http package.
108 | func parsePackage() ParsedPackage {
109 | pkgs, err := parser.ParseFile(token.NewFileSet(), "net/http", src, parser.ParseComments)
110 | if err != nil {
111 | println("parse", err.Error())
112 | panic("fail")
113 | }
114 | return pkgs
115 | }
116 |
--------------------------------------------------------------------------------
/sweet/cmd/sweet/get_cipd.go:
--------------------------------------------------------------------------------
1 | // Copyright 2021 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | //go:build !wasm && !plan9
6 |
7 | package main
8 |
9 | import (
10 | "context"
11 | "fmt"
12 | "os"
13 | "path/filepath"
14 |
15 | "go.chromium.org/luci/cipd/client/cipd"
16 | "go.chromium.org/luci/cipd/client/cipd/pkg"
17 | cipdc "go.chromium.org/luci/cipd/common"
18 | "go.chromium.org/luci/hardcoded/chromeinfra"
19 | "golang.org/x/benchmarks/sweet/cli/assets"
20 | "golang.org/x/benchmarks/sweet/common/log"
21 | )
22 |
23 | func (c *getCmd) Run(_ []string) error {
24 | log.SetActivityLog(true)
25 | ctx := context.Background()
26 |
27 | // Do some cleanup, if needed.
28 | if c.clean {
29 | for {
30 | log.Printf("Deleting cache directory %s", c.cache)
31 | fmt.Print("This is a destructive action. Please confirm. (y/n): ")
32 | var r string
33 | _, err := fmt.Scanf("%s\n", &r)
34 | if err != nil {
35 | fmt.Printf("Invalid input: %v\n", err)
36 | } else {
37 | if r == "y" {
38 | break
39 | } else if r == "n" {
40 | return nil
41 | } else {
42 | fmt.Println("Input must be exactly 'y' or 'n'.")
43 | }
44 | }
45 | }
46 | if err := os.RemoveAll(c.cache); err != nil {
47 | return fmt.Errorf("failed to delete cache directory %s: %v", c.cache, err)
48 | }
49 | }
50 |
51 | // Load CIPD options, including auth, cache dir, etc. from env. The package is public, but we
52 | // want to be authenticated transparently when we pull the assets down on the builders.
53 | var opts cipd.ClientOptions
54 | if err := opts.LoadFromEnv(ctx); err != nil {
55 | return err
56 | }
57 | if opts.ServiceURL == "" {
58 | opts.ServiceURL = chromeinfra.CIPDServiceURL
59 | }
60 | // Use an existing CIPD cache in the environment, if available.
61 | // Otherwise, set up the default.
62 | if opts.CacheDir == "" {
63 | opts.CacheDir = filepath.Join(c.cache, assets.CIPDCacheDir)
64 | }
65 |
66 | // Figure out the destination directory.
67 | var ensureOpts cipd.EnsureOptions
68 | ensureOpts.Paranoia = cipd.CheckIntegrity
69 | if c.copyDir != "" {
70 | ensureOpts.OverrideInstallMode = pkg.InstallModeCopy
71 | opts.Root = c.copyDir
72 | } else {
73 | assetsDir, err := assets.CachedAssets(c.cache, c.version)
74 | if err == nil {
75 | // Nothing to do.
76 | return nil
77 | }
78 | if err != assets.ErrNotInCache {
79 | return err
80 | }
81 | opts.Root = assetsDir
82 | }
83 |
84 | // Find the assets by version.
85 | cc, err := cipd.NewClient(opts)
86 | if err != nil {
87 | return err
88 | }
89 | defer cc.Close(ctx)
90 | pins, err := cc.SearchInstances(ctx, "golang/sweet/assets", []string{"version:" + assets.ToCIPDVersion(c.version)})
91 | if err != nil {
92 | return err
93 | }
94 | if len(pins) == 0 {
95 | return fmt.Errorf("unable to find CIPD package instance for version %s", c.version)
96 | }
97 |
98 | log.Printf("Fetching assets %s", c.version)
99 |
100 | // Fetch the instance.
101 | _, err = cc.EnsurePackages(ctx, map[string]cipdc.PinSlice{"": pins[:1]}, &ensureOpts)
102 | if err != nil {
103 | return fmt.Errorf("fetching CIPD package instance %s: %v", pins[0], err)
104 | }
105 | return nil
106 | }
107 |
--------------------------------------------------------------------------------
/sweet/cli/subcommands/sc.go:
--------------------------------------------------------------------------------
1 | // Copyright 2021 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package subcommands
6 |
7 | import (
8 | "flag"
9 | "fmt"
10 | "io"
11 | "os"
12 | "path/filepath"
13 | "unicode/utf8"
14 |
15 | "golang.org/x/benchmarks/sweet/common"
16 | "golang.org/x/benchmarks/sweet/common/log"
17 | )
18 |
19 | const (
20 | usageHeader = `Sweet %s: Go Benchmarking Suite
21 |
22 | `
23 | usageTop = `Sweet is a set of benchmarks derived from the Go community which are intended
24 | to represent a breadth of real-world applications. The primary use-case of this
25 | suite is to perform an evaluation of the difference in CPU and memory
26 | performance between two Go implementations.
27 |
28 | If you use this benchmarking suite for any measurements, please ensure you use
29 | a versioned release and note the version in the release.
30 |
31 | All results are reported in the standard Go testing package format, such that
32 | results may be compared using the benchstat tool.
33 |
34 | Usage: %s [subcommand flags] [subcommand args]
35 |
36 | Subcommands:
37 | `
38 | )
39 |
40 | var (
41 | base string
42 | cmds []*command
43 | out io.Writer
44 | )
45 |
46 | func init() {
47 | base = filepath.Base(os.Args[0])
48 | out = os.Stderr
49 | }
50 |
51 | type command struct {
52 | Command
53 | flags *flag.FlagSet
54 | }
55 |
56 | func (c *command) usage() {
57 | fmt.Fprintf(out, usageHeader, common.Version)
58 | c.PrintUsage(out, base)
59 | c.flags.PrintDefaults()
60 | }
61 |
62 | type Command interface {
63 | Name() string
64 | Synopsis() string
65 | PrintUsage(w io.Writer, base string)
66 | SetFlags(f *flag.FlagSet)
67 | Run(args []string) error
68 | }
69 |
70 | func Register(cmd Command) {
71 | f := flag.NewFlagSet(cmd.Name(), flag.ExitOnError)
72 | cmd.SetFlags(f)
73 | c := &command{
74 | Command: cmd,
75 | flags: f,
76 | }
77 | f.Usage = func() {
78 | c.usage()
79 | }
80 | cmds = append(cmds, c)
81 | }
82 |
83 | func usage() {
84 | fmt.Fprintf(out, usageHeader, common.Version)
85 | fmt.Fprintf(out, usageTop, base)
86 | maxnamelen := 10
87 | for _, c := range cmds {
88 | l := utf8.RuneCountInString(c.Name())
89 | if l > maxnamelen {
90 | maxnamelen = l
91 | }
92 | }
93 | for _, c := range cmds {
94 | fmt.Fprintf(out, fmt.Sprintf(" %%%ds: %%s\n", maxnamelen), c.Name(), c.Synopsis())
95 | }
96 | }
97 |
98 | func Run() int {
99 | if len(os.Args) < 2 {
100 | usage()
101 | os.Exit(1)
102 | }
103 | subcmd := os.Args[1]
104 | if subcmd == "help" {
105 | if len(os.Args) >= 3 {
106 | subhelp := os.Args[2]
107 | for _, cmd := range cmds {
108 | if cmd.Name() == subhelp {
109 | cmd.usage()
110 | return 0
111 | }
112 | }
113 | }
114 | usage()
115 | return 0
116 | }
117 | var chosen *command
118 | for _, cmd := range cmds {
119 | if cmd.Name() == subcmd {
120 | chosen = cmd
121 | break
122 | }
123 | }
124 | if chosen == nil {
125 | fmt.Fprintf(out, "unknown subcommand: %q\n", subcmd)
126 | fmt.Fprintln(out)
127 | usage()
128 | return 1
129 | }
130 | chosen.flags.Parse(os.Args[2:])
131 | if err := chosen.Run(chosen.flags.Args()); err != nil {
132 | log.Error(err)
133 | return 1
134 | }
135 | return 0
136 | }
137 |
--------------------------------------------------------------------------------
/sweet/benchmarks/internal/cgroups/cgroups.go:
--------------------------------------------------------------------------------
1 | // Copyright 2021 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package cgroups
6 |
7 | import (
8 | "errors"
9 | "fmt"
10 | "os"
11 | "os/exec"
12 | "os/user"
13 | "path/filepath"
14 | "strconv"
15 | "strings"
16 | "sync"
17 | "time"
18 | )
19 |
20 | func findSystemdRun() (string, error) {
21 | bin, err := exec.LookPath("systemd-run")
22 | if errors.Is(err, exec.ErrNotFound) {
23 | return "", fmt.Errorf("systemd-run binary not found")
24 | } else if err != nil {
25 | return "", fmt.Errorf("error looking for systemd-run: %w", err)
26 | }
27 |
28 | scope := fmt.Sprintf("systemd-run-test-%d.scope", time.Now().UnixNano())
29 |
30 | cmd := exec.Command(bin, "--user", "--scope", "--unit", scope, "/bin/true")
31 | sout, serr := cmd.CombinedOutput()
32 | if serr == nil {
33 | // It works!
34 | return bin, nil
35 | }
36 |
37 | var context strings.Builder
38 | fmt.Fprintf(&context, "\noutput: %s", string(sout))
39 |
40 | // Failed. systemd-run probably just said to look at journalctl;
41 | // collect that additional context.
42 | cmd = exec.Command("journalctl", "--catalog", "--user", "--unit", scope)
43 | jout, jerr := cmd.CombinedOutput()
44 | if jerr != nil {
45 | fmt.Fprintf(&context, "\njournalctl error: %v\noutout: %s", jerr, string(jout))
46 | } else {
47 | fmt.Fprintf(&context, "\njournalctl output: %s", string(jout))
48 | }
49 |
50 | // Attempt to cleanup unit.
51 | cmd = exec.Command("systemctl", "--user", "reset-failed", scope)
52 | scout, scerr := cmd.CombinedOutput()
53 | if scerr != nil {
54 | fmt.Fprintf(&context, "\nsystemctl cleanup error: %v\noutput: %s", scerr, string(scout))
55 | }
56 |
57 | return "", fmt.Errorf("system-run failed: %w%s", serr, context.String())
58 | }
59 |
60 | var (
61 | systemdOnce sync.Once
62 | systemdRunPath string
63 | systemdRunError error
64 | )
65 |
66 | type Cmd struct {
67 | exec.Cmd
68 | modified bool
69 | path string
70 | scope string
71 | }
72 |
73 | func WrapCommand(cmd *exec.Cmd, scope string) (*Cmd, error) {
74 | wrapped := Cmd{Cmd: *cmd}
75 |
76 | systemdOnce.Do(func() {
77 | systemdRunPath, systemdRunError = findSystemdRun()
78 | })
79 |
80 | if systemdRunError != nil {
81 | fmt.Fprintf(os.Stderr, "# warning: systemd-run not available: %v\n# skipping cgroup wrapper...\n", systemdRunError)
82 | return &wrapped, nil
83 | }
84 |
85 | u, err := user.Current()
86 | if err != nil {
87 | return nil, err
88 | }
89 | wrapped.Cmd.Args = append([]string{
90 | systemdRunPath, "--user", "--scope", "--unit=" + scope,
91 | }, wrapped.Cmd.Args...)
92 | wrapped.Cmd.Path = systemdRunPath
93 | wrapped.modified = true
94 | wrapped.path = fmt.Sprintf("user-%s.slice/user@%s.service/app.slice", u.Uid, u.Uid)
95 | wrapped.scope = scope
96 |
97 | return &wrapped, nil
98 | }
99 |
100 | func (c *Cmd) RSSFunc() func() (uint64, error) {
101 | if !c.modified {
102 | return nil
103 | }
104 | memPath := filepath.Join("/sys/fs/cgroup/user.slice", c.path, c.scope, "memory.current")
105 | return func() (uint64, error) {
106 | data, err := os.ReadFile(memPath)
107 | if err != nil {
108 | return 0, err
109 | }
110 | return strconv.ParseUint(strings.TrimSpace(string(data)), 10, 64)
111 | }
112 | }
113 |
--------------------------------------------------------------------------------
/sweet/common/env_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2021 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package common_test
6 |
7 | import (
8 | "reflect"
9 | "testing"
10 |
11 | "golang.org/x/benchmarks/sweet/common"
12 | )
13 |
14 | func stringSliceToSet(sl []string) map[string]struct{} {
15 | ss := make(map[string]struct{})
16 | for _, s := range sl {
17 | ss[s] = struct{}{}
18 | }
19 | return ss
20 | }
21 |
22 | func TestEnv(t *testing.T) {
23 | tryLookup := func(t *testing.T, env *common.Env, try, expect string) {
24 | if v, ok := env.Lookup(try); !ok {
25 | t.Fatalf("expected to find variable %q", try)
26 | } else if v != expect {
27 | t.Fatalf("expected to find value %q for %q, instead got %q", v, try, expect)
28 | }
29 | }
30 | tryBadLookup := func(t *testing.T, env *common.Env, try string) {
31 | if v, ok := env.Lookup(try); ok {
32 | t.Fatalf("expected to not find variable %q, got %q", try, v)
33 | }
34 | }
35 | tryCreate := func(t *testing.T, args ...string) *common.Env {
36 | env, err := common.NewEnv(args...)
37 | if err != nil {
38 | t.Fatalf("unexpected err: %v", err)
39 | }
40 | return env
41 | }
42 | trySet := func(t *testing.T, env *common.Env, args ...string) *common.Env {
43 | env2, err := env.Set(args...)
44 | if err != nil {
45 | t.Fatalf("unexpected err: %v", err)
46 | }
47 | return env2
48 | }
49 |
50 | env := tryCreate(t, "MYVAR=2", "MYVAR2=100")
51 |
52 | t.Run("BadCreate", func(t *testing.T) {
53 | _, err := common.NewEnv("MYVAR", "MYVAR2=100")
54 | if err == nil {
55 | t.Fatal("expected error due to bad input")
56 | }
57 | })
58 | t.Run("Lookup", func(t *testing.T) {
59 | tryLookup(t, env, "MYVAR", "2")
60 | })
61 | t.Run("EmptyLookup", func(t *testing.T) {
62 | tryBadLookup(t, env, "NOVAR")
63 | })
64 | t.Run("BadSet", func(t *testing.T) {
65 | _, err := env.Set("BADVAR")
66 | if err == nil {
67 | t.Fatal("expected error due to bad input")
68 | }
69 | })
70 | exp := stringSliceToSet([]string{"MYVAR=3", "OTHERVAR=6", "MYVAR2=100"})
71 | t.Run("Set", func(t *testing.T) {
72 | env2 := trySet(t, env, "MYVAR=3", "OTHERVAR=6")
73 | tryLookup(t, env2, "MYVAR", "3")
74 | tryLookup(t, env2, "OTHERVAR", "6")
75 | tryLookup(t, env2, "MYVAR2", "100")
76 | tryLookup(t, env, "MYVAR", "2")
77 | tryBadLookup(t, env, "OTHERVAR")
78 | l := stringSliceToSet(env2.Collapse())
79 | if !reflect.DeepEqual(l, exp) {
80 | t.Fatalf("on collapse got %v, expected %v", l, exp)
81 | }
82 | })
83 | t.Run("DeepSet", func(t *testing.T) {
84 | env2 := trySet(t, env, "OTHERVAR=6")
85 | env3 := trySet(t, env2, "MYVAR=3")
86 | tryLookup(t, env3, "MYVAR", "3")
87 | tryLookup(t, env3, "MYVAR2", "100")
88 | tryLookup(t, env3, "OTHERVAR", "6")
89 | tryLookup(t, env2, "OTHERVAR", "6")
90 | tryLookup(t, env2, "MYVAR2", "100")
91 | tryLookup(t, env2, "MYVAR", "2")
92 | tryLookup(t, env, "MYVAR", "2")
93 | tryBadLookup(t, env, "OTHERVAR")
94 | l := stringSliceToSet(env3.Collapse())
95 | if !reflect.DeepEqual(l, exp) {
96 | t.Fatalf("on collapse got %v, expected %v", l, exp)
97 | }
98 | })
99 | t.Run("Prefix", func(t *testing.T) {
100 | env2 := env.Prefix("MYVAR", "3")
101 | tryLookup(t, env2, "MYVAR", "32")
102 | tryLookup(t, env, "MYVAR", "2")
103 | })
104 | }
105 |
--------------------------------------------------------------------------------
/sweet/benchmarks/internal/pool/pool.go:
--------------------------------------------------------------------------------
1 | // Copyright 2021 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | /*
6 | This package provides a facility to run a heterogeneous pool of workers.
7 |
8 | Each worker is defined by an interface, and the pool execute's each worker's
9 | Run method repeatedly concurrently. The worker may exit early by returning
10 | the Done error. Each worker's Run method accepts a context.Context which is
11 | passed to it through the pool. If this context is cancelled, it may cancel
12 | workers and will always cancel the pool.
13 |
14 | Each worker is guaranteed to start immediately when the pool's Run method is
15 | called and not any sooner.
16 | */
17 | package pool
18 |
19 | import (
20 | "context"
21 | "errors"
22 | "sync"
23 |
24 | "golang.org/x/sync/errgroup"
25 | )
26 |
27 | // Done is used to signal to the pool that the worker has no more useful work
28 | // to do.
29 | var Done error = errors.New("pool worker is done")
30 |
31 | // Worker represents a stateful task which is executed repeatedly by calling
32 | // its Run method. Any resources associated with the Worker may be freed with
33 | // Close.
34 | type Worker interface {
35 | // Run executes a task once, returning an error on failure.
36 | Run(context.Context) error
37 |
38 | // Close releases any resources associated with the Worker.
39 | Close() error
40 | }
41 |
42 | // P implements a heterogeneous pool of Workers.
43 | type P struct {
44 | workers []Worker
45 | gun chan struct{}
46 | g *errgroup.Group
47 | }
48 |
49 | // New creates a new pool of the given workers.
50 | //
51 | // The provided context will be passed to all workers' run methods.
52 | func New(ctx context.Context, workers []Worker) *P {
53 | g, ctx := errgroup.WithContext(ctx)
54 | gun := make(chan struct{})
55 |
56 | var ready sync.WaitGroup
57 | ready.Add(len(workers))
58 |
59 | // Spin up workers.
60 | for _, w := range workers {
61 | w := w
62 | g.Go(func() error {
63 | ready.Done()
64 | <-gun // wait for starting gun to close
65 | for {
66 | err := w.Run(ctx)
67 | if err == Done || ctx.Err() != nil {
68 | return nil
69 | } else if err != nil {
70 | return err
71 | }
72 | }
73 | })
74 | }
75 |
76 | // Wait for all workers to be ready.
77 | ready.Wait()
78 |
79 | return &P{
80 | workers: workers,
81 | gun: gun,
82 | g: g,
83 | }
84 | }
85 |
86 | // Run signals all the workers to begin and waits for all of them to complete.
87 | //
88 | // Each Worker's Run method is called in a loop until the worker returns an
89 | // error or the context passed to New is cancelled. If the error is Done, then
90 | // it does not propagate to Run and instead the worker stops looping.
91 | //
92 | // If the context is cancelled for any reason no error is returned. Check the
93 | // context for any errors in that case.
94 | //
95 | // Always cleans up the pool's workers by calling Close before returning.
96 | //
97 | // Returns the first error encountered from any worker that failed and cancels
98 | // the rest immediately.
99 | func (p *P) Run() error {
100 | close(p.gun) // fire starting gun
101 | defer func() {
102 | // Clean up on exit.
103 | for _, w := range p.workers {
104 | w.Close()
105 | }
106 | }()
107 | return p.g.Wait()
108 | }
109 |
--------------------------------------------------------------------------------
/stats/edm_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2021 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package stats
6 |
7 | import (
8 | "reflect"
9 | "testing"
10 | )
11 |
12 | func TestNormalize(t *testing.T) {
13 | t.Parallel()
14 | tests := []struct {
15 | input, expected []float64
16 | }{
17 | {[]float64{}, []float64{}},
18 | {[]float64{0, 1}, []float64{0, 1}},
19 | {[]float64{1, 2, 3}, []float64{0, 0.5, 1}},
20 | {[]float64{-1, 0, 1}, []float64{0, 0.5, 1}},
21 | {[]float64{-3, -2, -1}, []float64{0, 0.5, 1}},
22 | {[]float64{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, []float64{0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1}},
23 | }
24 | for i, test := range tests {
25 | if out := normalize(test.input); !reflect.DeepEqual(out, test.expected) {
26 | t.Errorf("[%d] normalizeInput(%v) = %v, expected %v", i, test.input, out, test.expected)
27 | }
28 | }
29 | }
30 |
31 | func TestMedianResolution(t *testing.T) {
32 | t.Parallel()
33 | tests := []struct {
34 | l, expected int
35 | }{
36 | {1, 10},
37 | {1000, 10},
38 | {2048, 11},
39 | }
40 | for i, test := range tests {
41 | if v := medianResolution(test.l); v != test.expected {
42 | t.Errorf("[%d] medianResolution(%v) = %v, expected %v", i, test.l, v, test.expected)
43 | }
44 | }
45 | }
46 |
47 | func TestEDMXGolden(t *testing.T) {
48 | // This test case is used in the paper.
49 | input := []float64{
50 | 105.08333, 90.90000, 763.90000, 83.36667, 78.36667, 80.58333,
51 | 76.36667, 210.98333, 78.00000, 77.51667, 83.01667, 89.23333,
52 | 84.86667, 653.16667, 70.91667, 72.83333, 75.91667, 73.53333,
53 | 548.86667, 66.23333, 73.45000, 66.96667, 71.11667, 68.31667,
54 | 285.38333, 317.20000, 63.28333, 64.08333, 60.50000, 550.88333,
55 | 399.68333, 75.90000, 115.35000, 78.93333, 88.68333, 475.53333,
56 | 30.11667, 31.51667, 34.08333, 39.55000, 47.51667, 423.63333,
57 | 52.55000, 50.21667, 61.41667, 56.61667, 64.41667, 742.30000,
58 | 165.85000, 122.88333, 122.21667, 114.66667, 565.96667, 134.70000,
59 | 141.16667, 160.78333, 168.48333, 458.65000, 513.28333, 154.36667,
60 | 130.66667, 125.93333, 127.25000, 615.58333, 122.90000, 97.45000,
61 | 122.76667, 115.10000, 111.95000, 442.78333, 113.83333, 116.11667,
62 | 128.70000, 135.03333, 138.75000, 153.38333, 143.58333, 161.50000,
63 | 168.11667, 152.25000, 147.11667, 163.91667, 161.10000, 146.95000,
64 | 132.65000, 127.28333, 116.10000, 92.28333, 54.88333, 111.35000,
65 | 114.98333, 110.98333, 1015.35000, 774.58333, 232.65000, 134.61667,
66 | 130.25000, 98.66667, 102.40000, 184.86667, 258.76667, 70.33333,
67 | 81.38333, 81.10000, 89.21667, 536.96667, 85.83333, 95.63333,
68 | 76.10000, 94.38333, 73.25000, 346.70000, 65.38333, 84.73333,
69 | 140.56667, 120.60000, 121.38333, 359.23333, 55.28333, 54.55000,
70 | 52.18333, 56.20000, 112.11667, 208.53333, 49.40000, 49.06667,
71 | 56.06667, 54.01667, 63.51667, 344.41667, 42.06667, 55.36667,
72 | 55.96667, 55.85000, 56.30000, 46.56667, 49.25000, 43.90000,
73 | 357.61667, 44.10000, 44.68333, 43.13333, 40.55000, 452.20000,
74 | 47.06667, 40.00000, 42.35000, 48.36667, 44.86667, 48.51667,
75 | 244.01667, 50.16667, 48.73333, 47.91667, 51.96667, 343.33333,
76 | 35.25000, 45.33333, 46.86667, 48.78333}
77 | if v := EDMX(input, 24); v != 95 {
78 | t.Errorf("EDMX() = %v, expected 95", v)
79 | }
80 | if v := EDM(input, 24); v != 47 {
81 | t.Errorf("EDM() = %v, expected 47", v)
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/sweet/harnesses/local.go:
--------------------------------------------------------------------------------
1 | // Copyright 2021 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package harnesses
6 |
7 | import (
8 | "os/exec"
9 | "path/filepath"
10 |
11 | "golang.org/x/benchmarks/sweet/common"
12 | "golang.org/x/benchmarks/sweet/common/log"
13 | )
14 |
15 | type localBenchHarness struct {
16 | binName string
17 | genArgs func(cfg *common.Config, rcfg *common.RunConfig) []string
18 | beforeRun func(cfg *common.Config, rcfg *common.RunConfig) error
19 | }
20 |
21 | func (h *localBenchHarness) CheckPrerequisites() error {
22 | return nil
23 | }
24 |
25 | func (h *localBenchHarness) Get(_ *common.GetConfig) error {
26 | return nil
27 | }
28 |
29 | func (h *localBenchHarness) Build(cfg *common.Config, bcfg *common.BuildConfig) error {
30 | return cfg.GoTool(bcfg.BuildLog).BuildPath(bcfg.BenchDir, filepath.Join(bcfg.BinDir, h.binName))
31 | }
32 |
33 | func (h *localBenchHarness) Run(cfg *common.Config, rcfg *common.RunConfig) error {
34 | if h.beforeRun != nil {
35 | if err := h.beforeRun(cfg, rcfg); err != nil {
36 | return err
37 | }
38 | }
39 | cmd := exec.Command(
40 | filepath.Join(rcfg.BinDir, h.binName),
41 | append(rcfg.Args, h.genArgs(cfg, rcfg)...)...,
42 | )
43 | cmd.Env = cfg.ExecEnv.Collapse()
44 | cmd.Stdout = rcfg.Results
45 | cmd.Stderr = rcfg.Log
46 | log.TraceCommand(cmd, false)
47 | return cmd.Run()
48 | }
49 |
50 | func BiogoIgor() common.Harness {
51 | return &localBenchHarness{
52 | binName: "biogo-igor-bench",
53 | genArgs: func(cfg *common.Config, rcfg *common.RunConfig) []string {
54 | return []string{
55 | filepath.Join(rcfg.AssetsDir, "Homo_sapiens.GRCh38.dna.chromosome.22.gff"),
56 | }
57 | },
58 | }
59 | }
60 |
61 | func BiogoKrishna() common.Harness {
62 | return &localBenchHarness{
63 | binName: "biogo-krishna-bench",
64 | genArgs: func(cfg *common.Config, rcfg *common.RunConfig) []string {
65 | return []string{
66 | "-alignconc",
67 | "-tmp", rcfg.TmpDir,
68 | "-tmpconc",
69 | filepath.Join(rcfg.AssetsDir, "Mus_musculus.GRCm38.dna.nonchromosomal.fa"),
70 | }
71 | },
72 | }
73 | }
74 |
75 | func BleveIndex() common.Harness {
76 | return &localBenchHarness{
77 | binName: "bleve-index-bench",
78 | genArgs: func(cfg *common.Config, rcfg *common.RunConfig) []string {
79 | var args []string
80 | if rcfg.Short {
81 | args = []string{
82 | "-documents", "10",
83 | "-batch-size", "10",
84 | }
85 | } else {
86 | args = []string{
87 | "-documents", "1000",
88 | "-batch-size", "100",
89 | }
90 | }
91 | return append(args, filepath.Join(rcfg.AssetsDir, "enwiki-20080103-pages-articles.xml.bz2"))
92 | },
93 | }
94 | }
95 |
96 | func GopherLua() common.Harness {
97 | return &localBenchHarness{
98 | binName: "gopher-lua-bench",
99 | genArgs: func(cfg *common.Config, rcfg *common.RunConfig) []string {
100 | args := []string{
101 | filepath.Join(rcfg.AssetsDir, "k-nucleotide.lua"),
102 | filepath.Join(rcfg.AssetsDir, "input.txt"),
103 | }
104 | if rcfg.Short {
105 | args = append([]string{"-short"}, args...)
106 | }
107 | return args
108 | },
109 | }
110 | }
111 |
112 | func Markdown() common.Harness {
113 | return &localBenchHarness{
114 | binName: "markdown-bench",
115 | genArgs: func(cfg *common.Config, rcfg *common.RunConfig) []string {
116 | return []string{
117 | rcfg.AssetsDir,
118 | }
119 | },
120 | }
121 | }
122 |
--------------------------------------------------------------------------------
/sweet/harnesses/esbuild.go:
--------------------------------------------------------------------------------
1 | // Copyright 2024 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package harnesses
6 |
7 | import (
8 | "errors"
9 | "fmt"
10 | "os/exec"
11 | "path/filepath"
12 |
13 | "golang.org/x/benchmarks/sweet/common"
14 | "golang.org/x/benchmarks/sweet/common/log"
15 | )
16 |
17 | type ESBuild struct {
18 | haveYarn bool
19 | }
20 |
21 | func (h *ESBuild) CheckPrerequisites() error {
22 | // Check if we have the yarn command.
23 | if _, err := exec.LookPath("yarn"); err == nil {
24 | h.haveYarn = true
25 | } else if !errors.Is(err, exec.ErrNotFound) {
26 | return err
27 | }
28 | return nil
29 | }
30 |
31 | func (h *ESBuild) Get(gcfg *common.GetConfig) error {
32 | err := gitShallowClone(
33 | gcfg.SrcDir,
34 | "https://github.com/evanw/esbuild",
35 | "v0.23.1",
36 | )
37 | if err != nil {
38 | return err
39 | }
40 | runMake := func(rules ...string) error {
41 | cmd := exec.Command("make", append([]string{"-C", gcfg.SrcDir}, rules...)...)
42 | log.TraceCommand(cmd, false)
43 | if out, err := cmd.CombinedOutput(); err != nil {
44 | return fmt.Errorf("failed to run make: %v: output:\n%s", err, out)
45 | }
46 | return nil
47 | }
48 | // Fetch downstream benchmark dependencies.
49 | if err := runMake("bench/three"); err != nil {
50 | return err
51 | }
52 | if h.haveYarn {
53 | if err := runMake("bench/readmin"); err != nil {
54 | return err
55 | }
56 | }
57 | // Run the command but ignore errors. There's something weird going on with
58 | // a sed command in this make rule, but we don't actually need it to succeed
59 | // to run the benchmarks.
60 | _ = runMake("bench/rome")
61 | return nil
62 | }
63 |
64 | func (h *ESBuild) Build(cfg *common.Config, bcfg *common.BuildConfig) error {
65 | // Generate a symlink to the repository and put it in bin.
66 | // It's not a binary, but it's the only place we can put it
67 | // and still access it in Run.
68 | link := filepath.Join(bcfg.BinDir, "esbuild-src")
69 | err := symlink(link, bcfg.SrcDir)
70 | if err != nil {
71 | return err
72 | }
73 | // Build driver.
74 | if err := cfg.GoTool(bcfg.BuildLog).BuildPath(bcfg.BenchDir, filepath.Join(bcfg.BinDir, "esbuild-bench")); err != nil {
75 | return err
76 | }
77 | // Build esbuild.
78 | return cfg.GoTool(bcfg.BuildLog).BuildPath(filepath.Join(bcfg.SrcDir, "cmd", "esbuild"), filepath.Join(bcfg.BinDir, "esbuild"))
79 | }
80 |
81 | func (h *ESBuild) Run(cfg *common.Config, rcfg *common.RunConfig) error {
82 | for _, b := range esbuildBenchmarks {
83 | if b.needYarn && !h.haveYarn {
84 | continue
85 | }
86 | cmd := exec.Command(
87 | filepath.Join(rcfg.BinDir, "esbuild-bench"),
88 | "-bin", filepath.Join(rcfg.BinDir, "esbuild"),
89 | "-src", filepath.Join(rcfg.BinDir, "esbuild-src", b.src),
90 | "-tmp", rcfg.TmpDir,
91 | "-bench", b.name,
92 | )
93 | cmd.Args = append(cmd.Args, rcfg.Args...)
94 | cmd.Env = cfg.ExecEnv.Collapse()
95 | cmd.Stdout = rcfg.Results
96 | cmd.Stderr = rcfg.Log
97 | log.TraceCommand(cmd, false)
98 | if err := cmd.Run(); err != nil {
99 | return err
100 | }
101 | }
102 | return nil
103 | }
104 |
105 | type esbuildBenchmark struct {
106 | name string
107 | src string
108 | needYarn bool
109 | }
110 |
111 | var esbuildBenchmarks = []esbuildBenchmark{
112 | {"ThreeJS", filepath.Join("bench", "three"), false},
113 | {"RomeTS", filepath.Join("bench", "rome"), false},
114 | {"ReactAdminJS", filepath.Join("bench", "readmin"), true},
115 | }
116 |
--------------------------------------------------------------------------------
/sweet/common/fileutil/copy.go:
--------------------------------------------------------------------------------
1 | // Copyright 2021 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package fileutil
6 |
7 | import (
8 | "io"
9 | "io/fs"
10 | "os"
11 | "path/filepath"
12 | )
13 |
14 | // FileExists returns true if a file or directory exists at the
15 | // specified path, otherwise it returns false. If an error is
16 | // encountered while checking, an error is returned.
17 | func FileExists(path string) (bool, error) {
18 | _, err := os.Stat(path)
19 | if os.IsNotExist(err) {
20 | return false, nil
21 | } else if err != nil {
22 | return false, err
23 | }
24 | return true, nil
25 | }
26 |
27 | // CopyFile copies a file at path src to dst. sfinfo
28 | // is the os.FileInfo associated with the file at path src
29 | // and must be derived from it. sfinfo may be nil, in which
30 | // case the file at src is queried for its os.FileInfo,
31 | // and symbolic links are followed.
32 | //
33 | // In effect, sfinfo is just an optimization to avoid
34 | // querying the path for the os.FileInfo more than necessary.
35 | //
36 | // Thus, CopyFile always copies the bytes of the file at
37 | // src to a new file created at dst with the same file mode
38 | // as the old one.
39 | //
40 | // If srcFS != nil, then src is assumed to be a path within
41 | // srcFS.
42 | //
43 | // Returns a non-nil error if copying or acquiring the
44 | // os.FileInfo for the file fails.
45 | func CopyFile(dst, src string, sfinfo fs.FileInfo, srcFS fs.FS) error {
46 | var sf fs.File
47 | var err error
48 | if srcFS != nil {
49 | sf, err = srcFS.Open(src)
50 | } else {
51 | sf, err = os.Open(src)
52 | }
53 | if err != nil {
54 | return err
55 | }
56 | defer sf.Close()
57 | if sfinfo == nil || sfinfo.Mode()&os.ModeSymlink != 0 {
58 | sfinfo, err = sf.Stat()
59 | if err != nil {
60 | return err
61 | }
62 | }
63 | df, err := os.OpenFile(dst, os.O_RDWR|os.O_CREATE|os.O_TRUNC, sfinfo.Mode())
64 | if err != nil {
65 | return err
66 | }
67 | defer df.Close()
68 | _, err = io.Copy(df, sf)
69 | return err
70 | }
71 |
72 | // CopyDir recursively copies the directory at path src to
73 | // a new directory at path dst. If a symlink is encountered
74 | // along the way, it is deep-copied.
75 | //
76 | // If srcFS != nil, then src is assumed to be a path within
77 | // srcFS.
78 | //
79 | // dst and directories under dst may not retain the permissions
80 | // of src or the corresponding directories under src. Instead,
81 | // we always set the permissions of the new directories to 0755.
82 | func CopyDir(dst, src string, srcFS fs.FS) error {
83 | // Ignore the permissions of src, since if dst
84 | // isn't writable we can't actually copy files into it.
85 | // Pick a safe default that allows us to modify the
86 | // directory and files within however we want, but let
87 | // others only inspect it.
88 | if err := os.MkdirAll(dst, 0755); err != nil {
89 | return err
90 | }
91 | var des []fs.DirEntry
92 | var err error
93 | if srcFS != nil {
94 | des, err = fs.ReadDir(srcFS, src)
95 | } else {
96 | des, err = os.ReadDir(src)
97 | }
98 | if err != nil {
99 | return err
100 | }
101 | for _, de := range des {
102 | fi, err := de.Info()
103 | if err != nil {
104 | return err
105 | }
106 | d, s := filepath.Join(dst, fi.Name()), filepath.Join(src, fi.Name())
107 | if fi.IsDir() {
108 | if err := CopyDir(d, s, srcFS); err != nil {
109 | return err
110 | }
111 | } else {
112 | if err := CopyFile(d, s, fi, srcFS); err != nil {
113 | return err
114 | }
115 | }
116 | }
117 | return nil
118 | }
119 |
--------------------------------------------------------------------------------
/stats/edmx.go:
--------------------------------------------------------------------------------
1 | // Copyright 2021 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package stats
6 |
7 | import (
8 | "container/heap"
9 | "math"
10 | )
11 |
12 | type maxHeap []float64
13 |
14 | func (h maxHeap) Len() int { return len(h) }
15 | func (h maxHeap) Less(i, j int) bool { return h[i] > h[j] }
16 | func (h maxHeap) Swap(i, j int) { h[i], h[j] = h[j], h[i] }
17 | func (h *maxHeap) Push(x interface{}) {
18 | *h = append(*h, x.(float64))
19 | }
20 | func (h *maxHeap) Pop() interface{} {
21 | old := *h
22 | n := len(old)
23 | x := old[n-1]
24 | *h = old[0 : n-1]
25 | return x
26 | }
27 |
28 | type minHeap []float64
29 |
30 | func (h minHeap) Len() int { return len(h) }
31 | func (h minHeap) Less(i, j int) bool { return h[i] < h[j] }
32 | func (h minHeap) Swap(i, j int) { h[i], h[j] = h[j], h[i] }
33 | func (h *minHeap) Push(x interface{}) {
34 | *h = append(*h, x.(float64))
35 | }
36 | func (h *minHeap) Pop() interface{} {
37 | old := *h
38 | n := len(old)
39 | x := old[n-1]
40 | *h = old[0 : n-1]
41 | return x
42 | }
43 |
44 | // addToHeaps adds a value to the appropriate heap,and keeps their sizes close.
45 | // This is a direct translation of the addToHeaps function described in the
46 | // paper.
47 | func addToHeaps(min *minHeap, max *maxHeap, x float64) {
48 | // NB: There's an ambiguity in the paper here related to if-then/else
49 | // evaluation. This structure seems to yield the desired results.
50 | if min.Len() == 0 || x < (*min)[0] {
51 | heap.Push(max, x)
52 | } else {
53 | heap.Push(min, x)
54 | }
55 | if min.Len() > max.Len()+1 {
56 | heap.Push(max, heap.Pop(min))
57 | } else if max.Len() > min.Len()+1 {
58 | heap.Push(min, heap.Pop(max))
59 | }
60 | }
61 |
62 | // getMedian finds the median of the min and max heaps.
63 | // This is a direct translation of the getMedian function described in the
64 | // paper.
65 | func getMedian(min minHeap, max maxHeap) float64 {
66 | if min.Len() > max.Len() {
67 | return min[0]
68 | }
69 | if max.Len() > min.Len() {
70 | return max[0]
71 | }
72 | return (max[0] + min[0]) / 2
73 | }
74 |
75 | // edmx implements the EDM-X algorithm.
76 | // This algorithm runs in place, modifying the data.
77 | func edmx(input []float64, delta int) int {
78 | input = normalize(input)
79 | var lmax, rmax maxHeap
80 | var lmin, rmin minHeap
81 | heap.Init(&lmax)
82 | heap.Init(&rmax)
83 | heap.Init(&lmin)
84 | heap.Init(&rmin)
85 | bestStat := math.Inf(-1)
86 | bestLoc := -1
87 |
88 | for i := 0; i < delta-1; i++ {
89 | addToHeaps(&lmin, &lmax, input[i])
90 | }
91 | for i := delta; i < len(input)-delta+1; i++ {
92 | addToHeaps(&lmin, &lmax, input[i-1])
93 | ml := getMedian(lmin, lmax)
94 | rmax, rmin = rmax[:0], rmin[:0]
95 | for j := i; j < i+delta-1; j++ {
96 | addToHeaps(&rmin, &rmax, input[j])
97 | }
98 | for j := i + delta; j < len(input)+1; j++ {
99 | addToHeaps(&rmin, &rmax, input[j-1])
100 | mr := getMedian(rmin, rmax)
101 | stat := float64(i*(j-i)) / float64(j) * (ml - mr) * (ml - mr)
102 | if stat > bestStat {
103 | bestStat = stat
104 | bestLoc = i
105 | }
106 | }
107 | }
108 |
109 | return bestLoc
110 | }
111 |
112 | // EDMX runs the EDM-X algorithm on a slice of floats.
113 | func EDMX(input []float64, delta int) int {
114 | // edmx modifies the input, don't do that.
115 | c := make([]float64, len(input))
116 | copy(c, input)
117 | return edmx(c, delta)
118 | }
119 |
120 | // EDMXInt runs the EDM-X algorithm on a slice of integer datapoints.
121 | func EDMXInt(input []int, delta int) int {
122 | return edmx(toFloat(input), delta)
123 | }
124 |
--------------------------------------------------------------------------------
/go.mod:
--------------------------------------------------------------------------------
1 | module golang.org/x/benchmarks
2 |
3 | go 1.24.0
4 |
5 | require (
6 | github.com/BurntSushi/toml v1.0.0
7 | github.com/biogo/biogo v1.0.4
8 | github.com/biogo/graph v0.0.0-20150317020928-057c1989faed
9 | github.com/biogo/store v0.0.0-20201120204734-aad293a2328f
10 | github.com/blevesearch/bleve v1.0.14
11 | github.com/dustin/go-wikiparse v0.0.0-20211018054215-c01ec186f20c
12 | github.com/gomodule/redigo v1.9.2
13 | github.com/google/pprof v0.0.0-20241017200806-017d972448fc
14 | github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51
15 | github.com/opencontainers/runtime-spec v1.0.2
16 | github.com/yuin/gopher-lua v1.1.1
17 | gitlab.com/golang-commonmark/markdown v0.0.0-20211110145824-bf3e522c626a
18 | go.chromium.org/luci v0.0.0-20250606083430-318ed8f4881d
19 | go.etcd.io/etcd/client/v3 v3.5.8
20 | golang.org/x/sync v0.19.0
21 | golang.org/x/sys v0.39.0
22 | )
23 |
24 | require (
25 | cloud.google.com/go/compute/metadata v0.6.0 // indirect
26 | github.com/RoaringBitmap/roaring v0.4.23 // indirect
27 | github.com/blevesearch/go-porterstemmer v1.0.3 // indirect
28 | github.com/blevesearch/mmap-go v1.0.2 // indirect
29 | github.com/blevesearch/segment v0.9.0 // indirect
30 | github.com/blevesearch/snowballstem v0.9.0 // indirect
31 | github.com/blevesearch/zap/v11 v11.0.14 // indirect
32 | github.com/blevesearch/zap/v12 v12.0.14 // indirect
33 | github.com/blevesearch/zap/v13 v13.0.6 // indirect
34 | github.com/blevesearch/zap/v14 v14.0.5 // indirect
35 | github.com/blevesearch/zap/v15 v15.0.3 // indirect
36 | github.com/coreos/go-semver v0.3.0 // indirect
37 | github.com/coreos/go-systemd/v22 v22.3.2 // indirect
38 | github.com/couchbase/vellum v1.0.2 // indirect
39 | github.com/danjacques/gofslock v0.0.0-20240212154529-d899e02bfe22 // indirect
40 | github.com/glycerine/go-unsnap-stream v0.0.0-20181221182339-f9677308dec2 // indirect
41 | github.com/gogo/protobuf v1.3.2 // indirect
42 | github.com/golang/mock v1.6.0 // indirect
43 | github.com/golang/protobuf v1.5.4 // indirect
44 | github.com/golang/snappy v0.0.4 // indirect
45 | github.com/julienschmidt/httprouter v1.3.0 // indirect
46 | github.com/klauspost/compress v1.17.11 // indirect
47 | github.com/kr/pretty v0.3.1 // indirect
48 | github.com/mschoch/smat v0.2.0 // indirect
49 | github.com/philhofer/fwd v1.0.0 // indirect
50 | github.com/steveyen/gtreap v0.1.0 // indirect
51 | github.com/stretchr/testify v1.10.0 // indirect
52 | github.com/tinylib/msgp v1.1.0 // indirect
53 | github.com/willf/bitset v1.1.10 // indirect
54 | github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
55 | gitlab.com/golang-commonmark/html v0.0.0-20191124015941-a22733972181 // indirect
56 | gitlab.com/golang-commonmark/linkify v0.0.0-20191026162114-a0c2df6c8f82 // indirect
57 | gitlab.com/golang-commonmark/mdurl v0.0.0-20191124015652-932350d1cb84 // indirect
58 | gitlab.com/golang-commonmark/puny v0.0.0-20191124015043-9f83538fa04f // indirect
59 | go.etcd.io/bbolt v1.3.7 // indirect
60 | go.etcd.io/etcd/api/v3 v3.5.8 // indirect
61 | go.etcd.io/etcd/client/pkg/v3 v3.5.8 // indirect
62 | go.uber.org/atomic v1.7.0 // indirect
63 | go.uber.org/multierr v1.6.0 // indirect
64 | go.uber.org/zap v1.24.0 // indirect
65 | golang.org/x/crypto v0.46.0 // indirect
66 | golang.org/x/exp v0.0.0-20251125195548-87e1e737ad39 // indirect
67 | golang.org/x/net v0.48.0 // indirect
68 | golang.org/x/oauth2 v0.34.0 // indirect
69 | golang.org/x/term v0.38.0 // indirect
70 | golang.org/x/text v0.32.0 // indirect
71 | google.golang.org/api v0.218.0 // indirect
72 | google.golang.org/genproto/googleapis/api v0.0.0-20250127172529-29210b9bc287 // indirect
73 | google.golang.org/genproto/googleapis/rpc v0.0.0-20250127172529-29210b9bc287 // indirect
74 | google.golang.org/grpc v1.70.0 // indirect
75 | google.golang.org/protobuf v1.36.5 // indirect
76 | gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
77 | )
78 |
--------------------------------------------------------------------------------
/sweet/harnesses/etcd.go:
--------------------------------------------------------------------------------
1 | // Copyright 2021 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package harnesses
6 |
7 | import (
8 | "os"
9 | "os/exec"
10 | "path/filepath"
11 |
12 | "golang.org/x/benchmarks/sweet/common"
13 | "golang.org/x/benchmarks/sweet/common/log"
14 | )
15 |
16 | type Etcd struct{}
17 |
18 | func (h Etcd) CheckPrerequisites() error {
19 | return nil
20 | }
21 |
22 | func (h Etcd) Get(gcfg *common.GetConfig) error {
23 | // Build against the latest alpha.
24 | //
25 | // Because of the way etcd is released (as a binary blob),
26 | // deployed copies tend to be stuck with a specific Go version.
27 | // Improving performance of these versions doesn't really matter.
28 | // Instead, try to track something close to HEAD.
29 | return gitShallowClone(
30 | gcfg.SrcDir,
31 | "https://github.com/etcd-io/etcd",
32 | "v3.6.0-alpha.0",
33 | )
34 | }
35 |
36 | func (h Etcd) Build(cfg *common.Config, bcfg *common.BuildConfig) error {
37 | env := cfg.BuildEnv.Env
38 |
39 | // Add the Go tool to PATH, since etcd's Makefile doesn't provide enough
40 | // visibility into how etcd is built to allow us to pass this information
41 | // directly. Also set the GOROOT explicitly because it might have propagated
42 | // differently from the environment.
43 | env = env.Prefix("PATH", filepath.Join(cfg.GoRoot, "bin")+":")
44 | env = env.MustSet("GOROOT=" + cfg.GoRoot)
45 |
46 | cmd := exec.Command("make", "-C", bcfg.SrcDir, "build")
47 | cmd.Env = env.Collapse()
48 | log.TraceCommand(cmd, false)
49 | // Call Output here to get an *ExitError with a populated Stderr field.
50 | if _, err := cmd.Output(); err != nil {
51 | return err
52 | }
53 | // Note that no matter what we do, the build script insists on putting the
54 | // binaries into the source directory, so copy the one we care about into
55 | // BinDir.
56 | if err := copyFile(filepath.Join(bcfg.BinDir, "etcd"), filepath.Join(bcfg.SrcDir, "bin", "etcd")); err != nil {
57 | return err
58 | }
59 | // Build etcd's benchmarking tool. Our benchmark is just a wrapper around that.
60 | benchmarkPkg := filepath.Join(bcfg.SrcDir, "tools", "benchmark")
61 | if err := cfg.GoTool(bcfg.BuildLog).BuildPath(benchmarkPkg, filepath.Join(bcfg.BinDir, "benchmark")); err != nil {
62 | return err
63 | }
64 | // Build the benchmark wrapper.
65 | return cfg.GoTool(bcfg.BuildLog).BuildPath(bcfg.BenchDir, filepath.Join(bcfg.BinDir, "etcd-bench"))
66 | }
67 |
68 | func (h Etcd) Run(cfg *common.Config, rcfg *common.RunConfig) error {
69 | for _, bench := range []string{"put", "stm"} {
70 | args := append(rcfg.Args, []string{
71 | "-bench", bench,
72 | "-etcd-bin", filepath.Join(rcfg.BinDir, "etcd"),
73 | "-benchmark-bin", filepath.Join(rcfg.BinDir, "benchmark"),
74 | "-tmp", rcfg.TmpDir,
75 | }...)
76 | if rcfg.Short {
77 | args = append(args, "-short")
78 | }
79 | cmd := exec.Command(
80 | filepath.Join(rcfg.BinDir, "etcd-bench"),
81 | args...,
82 | )
83 | cmd.Env = cfg.ExecEnv.Collapse()
84 | cmd.Stdout = rcfg.Results
85 | cmd.Stderr = rcfg.Log
86 | log.TraceCommand(cmd, false)
87 | if err := cmd.Run(); err != nil {
88 | return err
89 | }
90 | // Delete tmp because etcd will have written something there and
91 | // might attempt to reuse it.
92 | if err := rmDirContents(rcfg.TmpDir); err != nil {
93 | return err
94 | }
95 | }
96 | return nil
97 | }
98 |
99 | func rmDirContents(dir string) error {
100 | log.CommandPrintf("rm -rf %s/*", dir)
101 | fs, err := os.ReadDir(dir)
102 | if err != nil {
103 | return err
104 | }
105 | for _, fi := range fs {
106 | if err := os.RemoveAll(filepath.Join(dir, fi.Name())); err != nil {
107 | return err
108 | }
109 | }
110 | return nil
111 | }
112 |
--------------------------------------------------------------------------------
/sweet/common/harness.go:
--------------------------------------------------------------------------------
1 | // Copyright 2021 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package common
6 |
7 | import (
8 | "io"
9 | "os"
10 | )
11 |
12 | type GetConfig struct {
13 | // SrcDir is the path to the directory that the harness should write
14 | // benchmark source into. This is then fed into the BuildConfig.
15 | //
16 | // The harness should not write benchmark source code from the Sweet
17 | // repository here; it need only collect source code it needs to fetch
18 | // from a remote source.
19 | SrcDir string
20 |
21 | // Short indicates whether or not to run a short version of the benchmarks
22 | // for testing. Guaranteed to be the same as BuildConfig.Short and
23 | // RunConfig.Short.
24 | Short bool
25 | }
26 |
27 | type BuildConfig struct {
28 | // BinDir is the path to the directory where all built binaries should be
29 | // placed.
30 | BinDir string
31 |
32 | // SrcDir is the path to the directory containing the benchmark's source
33 | // code, excluding benchmark code that is part of the Sweet repository.
34 | //
35 | // For instance, this directory would contain a pulled source repository.
36 | SrcDir string
37 |
38 | // BenchDir is the path to the benchmark's source directory in the Sweet
39 | // repository.
40 | BenchDir string
41 |
42 | // Short indicates whether or not to run a short version of the benchmarks
43 | // for testing. Guaranteed to be the same as GetConfig.Short and
44 | // RunConfig.Short.
45 | Short bool
46 |
47 | // BuildLog is used to pass the build log to a file.
48 | BuildLog io.Writer
49 | }
50 |
51 | type RunConfig struct {
52 | // BinDir is the path to the directory containing the benchmark
53 | // binaries.
54 | BinDir string
55 |
56 | // TmpDir is the path to a dedicated scratch directory.
57 | //
58 | // This directory is empty at the beginning of each run.
59 | TmpDir string
60 |
61 | // AssetsDir is the path to the directory containing runtime assets
62 | // for the benchmark.
63 | //
64 | // AssistsDir is reconstructed for each run, so files within are safe
65 | // to mutate.
66 | AssetsDir string
67 |
68 | // Args is a set of additional command-line arguments to pass to the
69 | // primary benchmark binary (e.g. -dump-cores).
70 | //
71 | // The purpose of this field is to plumb through flags that all
72 | // benchmarks support, such as flags for generating CPU profiles and
73 | // such.
74 | Args []string
75 |
76 | // Results is the file to which benchmark results should be appended
77 | // in the Go benchmark format.
78 | //
79 | // By convention, this is the benchmark binary's stdout.
80 | Results *os.File
81 |
82 | // Log contains additional information from the benchmark,
83 | // for example for debugging.
84 | //
85 | // By convention, this is the benchmark binary's stderr.
86 | Log *os.File
87 |
88 | // Short indicates whether or not to run a short version of the benchmarks
89 | // for testing. Guaranteed to be the same as GetConfig.Short and
90 | // BuildConfig.Short.
91 | Short bool
92 | }
93 |
94 | type Harness interface {
95 | // CheckPrerequisites checks benchmark-specific environment prerequisites
96 | // such as whether we're running as root or on a specific platform.
97 | //
98 | // Returns an error if any prerequisites are not met, nil otherwise.
99 | CheckPrerequisites() error
100 |
101 | // Get retrieves the source code for a benchmark and places it in srcDir.
102 | Get(g *GetConfig) error
103 |
104 | // Build builds a benchmark and places the binaries in binDir.
105 | Build(cfg *Config, b *BuildConfig) error
106 |
107 | // Run runs the given benchmark and writes Go `testing` formatted benchmark
108 | // output to `results`.
109 | Run(cfg *Config, r *RunConfig) error
110 | }
111 |
--------------------------------------------------------------------------------
/sweet/benchmarks/internal/server/server.go:
--------------------------------------------------------------------------------
1 | // Copyright 2023 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package server
6 |
7 | import (
8 | "context"
9 | "errors"
10 | "fmt"
11 | "io"
12 | "net/http"
13 | "os"
14 | "sync"
15 | "time"
16 |
17 | "golang.org/x/benchmarks/sweet/benchmarks/internal/driver"
18 | "golang.org/x/benchmarks/sweet/common/diagnostics"
19 | )
20 |
21 | // FetchDiagnostic reads a profile or trace from the pprof endpoint at host. The
22 | // returned stop function finalizes the diagnostic file on disk and returns the
23 | // total size in bytes. Because of limitations of net/http/pprof, this cannot
24 | // actually stop collection on the server side, so stop should only be called
25 | // when the server is about to be shut down.
26 | func FetchDiagnostic(host string, diag *driver.Diagnostics, typ diagnostics.Type, name string) (stop func()) {
27 | if typ.HTTPEndpoint() == "" {
28 | panic("diagnostic " + string(typ) + " has no endpoint")
29 | }
30 |
31 | if !driver.DiagnosticEnabled(typ) {
32 | return func() {}
33 | }
34 |
35 | // If this is a snapshot-type diagnostic, wait until the end to collect it.
36 | if typ.IsSnapshot() {
37 | return func() {
38 | err := collectTo(context.Background(), host, diag, typ, name)
39 | if err != nil {
40 | fmt.Fprintf(os.Stderr, "failed to read diagnostic %s: %v", typ, err)
41 | }
42 | }
43 | }
44 |
45 | // Otherwise, start collecting it now. If it can be truncated, then we try
46 | // to collect it in one long run and cut if off when stop is called.
47 | // If it can be merged, we can collect several of them.
48 | var wg sync.WaitGroup
49 | wg.Add(1)
50 | ctx, cancel := context.WithCancel(context.Background())
51 | go func() {
52 | defer wg.Done()
53 |
54 | // If we can't truncate this diagnostic, make sure we collect it at
55 | // least once. This is important for PGO, which first does a profiling run.
56 | ctx1 := ctx
57 | if typ.CanMerge() && !typ.CanTruncate() {
58 | var cancel1 func()
59 | ctx1, cancel1 = context.WithTimeout(context.Background(), 5*time.Second)
60 | defer cancel1()
61 | }
62 |
63 | for {
64 | err := collectTo(ctx1, host, diag, typ, name)
65 | ctx1 = ctx
66 | if err != nil {
67 | if !errors.Is(err, context.Canceled) {
68 | fmt.Fprintf(os.Stderr, "failed to read diagnostic %s: %v", typ, err)
69 | }
70 | break
71 | }
72 | if !typ.CanMerge() {
73 | break
74 | }
75 | }
76 | }()
77 | return func() {
78 | // Stop the loop.
79 | cancel()
80 | wg.Wait()
81 | }
82 | }
83 |
84 | func collectTo(ctx context.Context, host string, diag *driver.Diagnostics, typ diagnostics.Type, name string) error {
85 | // Construct the endpoint URL
86 | var endpoint string
87 | endpoint = fmt.Sprintf("http://%s/%s", host, typ.HTTPEndpoint())
88 | if typ.CanMerge() && !typ.CanTruncate() {
89 | // Collect in lots of small increments because we won't be able to just
90 | // stop it.
91 | endpoint += "?seconds=1"
92 | } else if typ.CanTruncate() {
93 | // Collect a long run that we can cut off.
94 | endpoint += "?seconds=999999"
95 | }
96 |
97 | // Start profile collection.
98 | req, err := http.NewRequestWithContext(ctx, "GET", endpoint, nil)
99 | if err != nil {
100 | return err
101 | }
102 | resp, err := http.DefaultClient.Do(req)
103 | if err != nil {
104 | return err
105 | }
106 | defer resp.Body.Close()
107 |
108 | // Read into a diagnostic file
109 | f, err := diag.CreateNamed(typ, name)
110 | if err != nil {
111 | return err
112 | }
113 | defer f.Close()
114 |
115 | _, err = io.Copy(f, resp.Body)
116 | if err == nil || typ.CanTruncate() {
117 | // If we got a complete file, or it's fine to truncate it anyway, commit
118 | // the diagnostic file.
119 | f.Close()
120 | f.Commit()
121 | }
122 | return err
123 | }
124 |
--------------------------------------------------------------------------------
/driver/driver_linux.go:
--------------------------------------------------------------------------------
1 | // Copyright 2013 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | //go:build linux
6 |
7 | package driver
8 |
9 | import (
10 | "bufio"
11 | "bytes"
12 | "io"
13 | "log"
14 | "os"
15 | "os/exec"
16 | "regexp"
17 | "runtime"
18 | "strconv"
19 | "strings"
20 | "syscall"
21 | "unsafe"
22 |
23 | "golang.org/x/sys/unix"
24 | )
25 |
26 | const rssMultiplier = 1 << 10
27 |
28 | // Runs the cmd under perf. Returns filename of the profile. Any errors are ignored.
29 | func RunUnderProfiler(args ...string) (string, string) {
30 | cmd := exec.Command("perf", append([]string{"record", "-o", "perf.data"}, args...)...)
31 | out, err := cmd.CombinedOutput()
32 | if err != nil {
33 | log.Printf("Failed to execute 'perf record %v': %v\n%v", args, err, string(out))
34 | return "", ""
35 | }
36 |
37 | perf1 := perfReport("--sort", "comm")
38 | perf2 := perfReport()
39 | return perf1, perf2
40 | }
41 |
42 | func perfReport(args ...string) string {
43 | var stdout bytes.Buffer
44 | var stderr bytes.Buffer
45 | cmd := exec.Command("perf", append([]string{"report", "--stdio"}, args...)...)
46 | cmd.Stdout = &stdout
47 | cmd.Stderr = &stderr
48 | if err := cmd.Run(); err != nil {
49 | log.Printf("Failed to execute 'perf report': %v\n%v", err, stderr.String())
50 | return ""
51 | }
52 |
53 | f, err := os.Create(tempFilename("perf.txt"))
54 | if err != nil {
55 | log.Printf("Failed to create profile file: %v", err)
56 | return ""
57 | }
58 | defer f.Close()
59 |
60 | ff := bufio.NewWriter(f)
61 | defer ff.Flush()
62 |
63 | // Strip lines starting with #, and limit output to 100 lines.
64 | r := bufio.NewReader(&stdout)
65 | for n := 0; n < 100; {
66 | ln, err := r.ReadBytes('\n')
67 | if err == io.EOF {
68 | break
69 | }
70 | if err != nil {
71 | log.Printf("Failed to scan profile: %v", err)
72 | return ""
73 | }
74 | if len(ln) == 0 || ln[0] == '#' {
75 | continue
76 | }
77 | ff.Write(ln)
78 | n++
79 | }
80 |
81 | return f.Name()
82 | }
83 |
84 | // Size runs size command on the file. Returns filename with output. Any errors are ignored.
85 | func Size(file string) string {
86 | resf, err := os.Create(tempFilename("size.txt"))
87 | if err != nil {
88 | log.Printf("Failed to create output file: %v", err)
89 | return ""
90 | }
91 | defer resf.Close()
92 |
93 | var stderr bytes.Buffer
94 | cmd := exec.Command("size", "-A", file)
95 | cmd.Stdout = resf
96 | cmd.Stderr = &stderr
97 | if err := cmd.Run(); err != nil {
98 | log.Printf("Failed to execute 'size -m %v': %v\n%v", file, err, stderr.String())
99 | return ""
100 | }
101 |
102 | return resf.Name()
103 | }
104 |
105 | func getVMPeak() uint64 {
106 | data, err := os.ReadFile("/proc/self/status")
107 | if err != nil {
108 | log.Printf("Failed to read /proc/self/status: %v", err)
109 | return 0
110 | }
111 |
112 | re := regexp.MustCompile("VmPeak:[ \t]*([0-9]+) kB")
113 | match := re.FindSubmatch(data)
114 | if match == nil {
115 | log.Printf("No VmPeak in /proc/self/status")
116 | return 0
117 | }
118 | v, err := strconv.ParseUint(string(match[1]), 10, 64)
119 | if err != nil {
120 | log.Printf("Failed to parse VmPeak in /proc/self/status: %v", string(match[1]))
121 | return 0
122 | }
123 | return v * 1024
124 | }
125 |
126 | func setProcessAffinity(v int) {
127 | runtime.LockOSThread()
128 | defer runtime.UnlockOSThread()
129 | _, _, errno := syscall.Syscall(uintptr(unix.SYS_SCHED_SETAFFINITY), uintptr(syscall.Getpid()), uintptr(unsafe.Sizeof(v)), uintptr(unsafe.Pointer(&v)))
130 | if errno != 0 {
131 | log.Printf("failed to set affinity to %v: %v", v, errno.Error())
132 | return
133 | }
134 | // Re-exec the process w/o affinity flag.
135 | var args []string
136 | for i := 0; i < len(os.Args); i++ {
137 | a := os.Args[i]
138 | if strings.HasPrefix(a, "-affinity") {
139 | if a == "-affinity" {
140 | i++ // also skip the value
141 | }
142 | continue
143 | }
144 | args = append(args, a)
145 | }
146 | if err := syscall.Exec(os.Args[0], args, os.Environ()); err != nil {
147 | log.Printf("failed to exec: %v", err)
148 | }
149 | }
150 |
--------------------------------------------------------------------------------
/cmd/bench/bent.go:
--------------------------------------------------------------------------------
1 | // Copyright 2021 The Go Authors. All rights reserved.
2 | // Use of this source code is governed by a BSD-style
3 | // license that can be found in the LICENSE file.
4 |
5 | package main
6 |
7 | import (
8 | "bytes"
9 | "fmt"
10 | "log"
11 | "os"
12 | "os/exec"
13 | "path/filepath"
14 | "runtime"
15 | "text/template"
16 | )
17 |
18 | // TODO(prattmic): refactor bent to export Todo so we can directly build this
19 | // in Go.
20 | var configurationTmpl = template.Must(template.New("configuration").Parse(`
21 | {{- range . -}}
22 | [[Configurations]]
23 | Name = "{{.Name}}"
24 | Root = "{{.GOROOT}}"
25 | AfterBuild = ["benchsize"]
26 |
27 | {{end -}}
28 | `))
29 |
30 | func writeBentConfiguration(filename string, tcs []*toolchain) error {
31 | var buf bytes.Buffer
32 | if err := configurationTmpl.Execute(&buf, tcs); err != nil {
33 | return fmt.Errorf("error generating configuration: %w", err)
34 | }
35 |
36 | log.Printf("bent configuration:\n%s", buf.String())
37 |
38 | if err := os.WriteFile(filename, buf.Bytes(), 0644); err != nil {
39 | return fmt.Errorf("error creating configurations.toml: %w", err)
40 | }
41 | return nil
42 | }
43 |
44 | // removeAllIncludingReadonly is like os.RemoveAll except that it'll
45 | // also try to change permissions to work around permission errors
46 | // when deleting.
47 | func removeAllIncludingReadonly(dir string) error {
48 | err := os.RemoveAll(dir)
49 | if err == nil || !os.IsPermission(err) || runtime.GOOS == "windows" /* different fs permission model */ {
50 | return err
51 | }
52 | // Make a best effort (ignoring errors) attempt to make all
53 | // files and directories writable before we try to delete them
54 | // all again.
55 | filepath.Walk(dir, func(path string, fi os.FileInfo, err error) error {
56 | const ownerWritable = 0200
57 | if err != nil || fi.Mode().Perm()&ownerWritable != 0 {
58 | return nil
59 | }
60 | os.Chmod(path, fi.Mode().Perm()|ownerWritable)
61 | return nil
62 | })
63 | return os.RemoveAll(dir)
64 | }
65 |
66 | func bent(tcs []*toolchain, pgo bool) (err error) {
67 | if pgo {
68 | log.Printf("Skipping bent benchmarks (PGO not supported)")
69 | return nil
70 | }
71 | dir, err := os.MkdirTemp("", "bent")
72 | if err != nil {
73 | return fmt.Errorf("error creating temporary directory: %w", err)
74 | }
75 | defer func() {
76 | r := removeAllIncludingReadonly(dir)
77 | if r != nil && err == nil {
78 | err = fmt.Errorf("error removing temporary directory: %w", err)
79 | } else if r != nil {
80 | log.Printf("error removing temporary directory: %v", err)
81 | }
82 | }()
83 | log.Printf("Bent temporary directory: %s", dir)
84 |
85 | log.Printf("Building bent...")
86 |
87 | // Build bent itself. Just pick any toolchain we have; it doesn't matter which.
88 | // We're not benchmarking bent itself, it's just a driver.
89 | bentPath := filepath.Join(dir, "bent")
90 | if err := tcs[0].BuildPackage("golang.org/x/benchmarks/cmd/bent", bentPath); err != nil {
91 | return fmt.Errorf("building bent: %w", err)
92 | }
93 |
94 | log.Printf("Initializing bent...")
95 |
96 | // Initialize scratch dir for bent.
97 | cmd := exec.Command(bentPath, "-I")
98 | cmd.Dir = dir
99 | cmd.Stdout = os.Stdout
100 | cmd.Stderr = os.Stderr
101 | if err := cmd.Run(); err != nil {
102 | return fmt.Errorf("error running bent -I: %w", err)
103 | }
104 |
105 | confFile := filepath.Join(dir, "configurations.toml")
106 | if err := writeBentConfiguration(confFile, tcs); err != nil {
107 | return fmt.Errorf("error writing configuration: %w", err)
108 | }
109 |
110 | log.Printf("Running bent...")
111 |
112 | // Finally we can actually run the benchmarks.
113 | // N.B. bent prints the "toolchain" tag to indicate which toolchain is being used.
114 | // It's passed to bent via the TOML configuration.
115 | cmd = exec.Command(bentPath,
116 | "-N", "10",
117 | "-C", confFile,
118 | "-B", filepath.Join(dir, "benchmarks-50.toml"),
119 | "-report-build-time=false", // We only run builds once, which won't yield statistically significant results.
120 | "-v",
121 | )
122 | cmd.Dir = dir
123 | cmd.Stdout = os.Stdout
124 | cmd.Stderr = os.Stderr
125 | if err := cmd.Run(); err != nil {
126 | return fmt.Errorf("error running bent: %w", err)
127 | }
128 | return nil
129 | }
130 |
--------------------------------------------------------------------------------
/third_party/biogo-examples/igor/turner/cluster.go:
--------------------------------------------------------------------------------
1 | // Copyright ©2014 The bíogo Authors. All rights reserved.
2 | // Copyright 2021 The Go Authors. All rights reserved.
3 | // Use of this source code is governed by a BSD-style
4 | // license that can be found in the LICENSE file.
5 |
6 | package turner
7 |
8 | import (
9 | "sort"
10 |
11 | "github.com/biogo/biogo/align/pals"
12 | "github.com/biogo/biogo/feat"
13 | "github.com/biogo/store/interval"
14 | )
15 |
16 | type pairings struct {
17 | interval interval.IntRange
18 | id uintptr
19 |
20 | loc
21 | data []*pals.Feature
22 | }
23 |
24 | type loc struct{ feat.Feature }
25 |
26 | func (p *pairings) Start() int { return p.interval.Start }
27 | func (p *pairings) End() int { return p.interval.End }
28 | func (p *pairings) Len() int { return p.interval.End - p.interval.Start }
29 |
30 | func (p *pairings) ID() uintptr { return p.id }
31 | func (p *pairings) Range() interval.IntRange { return p.interval }
32 | func (p *pairings) Overlap(b interval.IntRange) bool {
33 | return b.End >= p.Start() && b.Start <= p.End()
34 | }
35 |
36 | type byDepth []*pairings
37 |
38 | func (p byDepth) Len() int { return len(p) }
39 | func (p byDepth) Less(i, j int) bool {
40 | return len(p[i].data) > len(p[j].data)
41 | }
42 | func (p byDepth) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
43 |
44 | type simple interval.IntRange
45 |
46 | func (i simple) Range() interval.IntRange { return interval.IntRange(i) }
47 | func (i simple) ID() uintptr { return 0 }
48 | func (i simple) Overlap(b interval.IntRange) bool {
49 | return b.End >= i.Start && b.Start <= i.End
50 | }
51 |
52 | // Cluster performs a clustering of images in the pile p to create a collection
53 | // of piles where image ends are within h times the images length of the ends of
54 | // the generated sub-pile. Clustering is seeded by the set of unique image intervals
55 | // in order of decreasing depth.
56 | func Cluster(p *pals.Pile, h float64) []*pals.Pile {
57 | pm := make(map[interval.IntRange][]*pals.Feature)
58 | for _, fv := range p.Images {
59 | i := interval.IntRange{Start: fv.Start(), End: fv.End()}
60 | c := pm[i]
61 | c = append(c, fv)
62 | pm[i] = c
63 | }
64 |
65 | pl := make([]*pairings, 0, len(pm))
66 | for iv, data := range pm {
67 | pl = append(pl, &pairings{interval: iv, loc: loc{p}, data: data})
68 | }
69 |
70 | var t interval.IntTree
71 | for i, pe := range pl {
72 | pe.id = uintptr(i)
73 | t.Insert(pe, true)
74 | }
75 | t.AdjustRanges()
76 |
77 | var cl []*pals.Pile
78 |
79 | sort.Sort(byDepth(pl))
80 | for _, pe := range pl {
81 | if _, ok := pm[interval.IntRange{Start: pe.Start(), End: pe.End()}]; !ok {
82 | continue
83 | }
84 | thr := int(h * float64(pe.interval.End-pe.interval.Start))
85 | from := pe.End()
86 | to := pe.Start()
87 | var (
88 | mf []*pals.Feature
89 | dm []interval.IntInterface
90 | )
91 | t.DoMatching(func(iv interval.IntInterface) (done bool) {
92 | r := iv.Range()
93 | if abs(pe.Start()-r.Start) <= thr && abs(pe.End()-r.End) <= thr {
94 | ivp := iv.(*pairings)
95 | dm = append(dm, iv)
96 | mf = append(mf, ivp.data...)
97 |
98 | if r.Start < from {
99 | from = r.Start
100 | }
101 | if r.End > to {
102 | to = r.End
103 | }
104 | }
105 | return
106 | }, simple{pe.Start() - thr, pe.End() + thr})
107 | if len(mf) == 0 {
108 | continue
109 | }
110 | for _, de := range dm {
111 | t.Delete(de, true)
112 | delete(pm, de.Range())
113 | }
114 | t.AdjustRanges()
115 | cl = append(cl, &pals.Pile{
116 | From: from,
117 | To: to,
118 | Loc: pe.Location(),
119 | Images: mf,
120 | })
121 | }
122 |
123 | return cl
124 | }
125 |
126 | func abs(a int) int {
127 | if a != 0 && a == -a {
128 | panic("weird number")
129 | }
130 | if a < 0 {
131 | return -a
132 | }
133 | return a
134 | }
135 |
136 | // Range returns the start and end positions for all the members of p.
137 | func Range(p []*pals.Pile) (start, end int) {
138 | if len(p) == 0 {
139 | return
140 | }
141 | start, end = p[0].Start(), p[0].End()
142 | for _, pi := range p[1:] {
143 | if s := pi.Start(); s < start {
144 | start = s
145 | }
146 | if e := pi.End(); e > end {
147 | end = e
148 | }
149 | }
150 | return start, end
151 | }
152 |
153 | // Volume returns the number of bases contributing to the pile p.
154 | func Volume(p *pals.Pile) int {
155 | var m int
156 | for _, im := range p.Images {
157 | m += im.Len()
158 | }
159 | return m
160 | }
161 |
162 | // ByVolume allows a collection of pals.Pile to be sorted by volume.
163 | type ByVolume []*pals.Pile
164 |
165 | func (p ByVolume) Len() int { return len(p) }
166 | func (p ByVolume) Less(i, j int) bool { return Volume(p[i]) > Volume(p[j]) }
167 | func (p ByVolume) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
168 |
169 | // ByDepth allows a collection of pals.Pile to be sorted by the number
170 | // images in each pile.
171 | type ByDepth []*pals.Pile
172 |
173 | func (p ByDepth) Len() int { return len(p) }
174 | func (p ByDepth) Less(i, j int) bool { return len(p[i].Images) > len(p[j].Images) }
175 | func (p ByDepth) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
176 |
--------------------------------------------------------------------------------
/cmd/bent/configs/benchmarks-50.toml:
--------------------------------------------------------------------------------
1 |
2 | # A sample of about 50 different benchmark runs, not noisy, run quickly enough,
3 | # that appear to be somewhat diverse.
4 |
5 | [[Benchmarks]]
6 | Name = "wazero"
7 | Benchmarks = "BenchmarkInvocation/interpreter/(string_manipulation_size_50|fib_for_20|random_mat_mul_size_20)|BenchmarkCompilation/with"
8 |
9 | [[Benchmarks]]
10 | Name = "toml"
11 | Benchmarks = "BenchmarkDecode/large-doc"
12 |
13 | [[Benchmarks]]
14 | Name = "minio"
15 | Tests = "none" # Don't run these tests; they hang, etc.
16 | Benchmarks = "Benchmark(MarshalMsgdataUsageCacheInfo|DecodehealingTracker|DataUpdateTracker|AppendMsgResyncTargetsInfo)"
17 | GcEnv = ["GO111MODULE=on"]
18 |
19 | [[Benchmarks]]
20 | Name = "hugo_hugolib"
21 | Benchmarks = "Benchmark(ResourceChainPostProcess|ReplaceShortcodeTokens|MergeByLanguage|(Cascade/langs-1-8))"
22 |
23 | [[Benchmarks]]
24 | Name = "ethereum_core"
25 | Benchmarks = "BenchmarkP.*10000"
26 |
27 | [[Benchmarks]]
28 | Name = "shopify_sarama"
29 | Benchmarks = "BenchmarkBroker" # BenchmarkStick.* are noisy
30 |
31 | [[Benchmarks]]
32 | Name = "aws_restjson"
33 | Benchmarks = "Benchmark"
34 |
35 | [[Benchmarks]]
36 | Name = "aws_restxml"
37 | Benchmarks = "Benchmark"
38 |
39 | [[Benchmarks]]
40 | Name = "aws_jsonrpc"
41 | Benchmarks = "Benchmark"
42 |
43 | [[Benchmarks]]
44 | Name = "aws_jsonutil"
45 | Benchmarks = "Benchmark"
46 |
47 | [[Benchmarks]]
48 | Name = "ethereum_bitutil"
49 | Benchmarks = "Benchmark(BaseTest2KB|FastTest2KB|Encoding4KBVerySparse)"
50 |
51 | [[Benchmarks]]
52 | Name = "ethereum_ethash"
53 | Benchmarks = "BenchmarkHashimotoLight"
54 |
55 | [[Benchmarks]]
56 | Name = "ethereum_sha3"
57 | Benchmarks = "BenchmarkSha3_224_MTU"
58 |
59 | [[Benchmarks]]
60 | Name = "ethereum_ecies"
61 | Benchmarks = "Benchmark"
62 |
63 | [[Benchmarks]]
64 | Name = "ethereum_corevm"
65 | Benchmarks = "BenchmarkOpDiv128"
66 |
67 | [[Benchmarks]]
68 | Name = "ethereum_trie"
69 | Benchmarks = "Benchmark[HCKGU].*/10K" # Prove and VerifyProof are noisy
70 |
71 | [[Benchmarks]]
72 | Name = "spexs2"
73 | Benchmarks = "BenchmarkRun/10k/1"
74 |
75 | [[Benchmarks]]
76 | Name = "gonum_blas_native"
77 | Benchmarks = "Benchmark(DasumMediumUnitaryInc|Dnrm2MediumPosInc)" # not all benchmarks
78 |
79 | [[Benchmarks]]
80 | Name = "gonum_lapack_native"
81 | Benchmarks = "BenchmarkDgeev/Circulant10"
82 |
83 | [[Benchmarks]]
84 | Name = "gonum_mat"
85 | Benchmarks = "Benchmark(MulWorkspaceDense1000Hundredth|ScaleVec10000Inc20)"
86 |
87 | [[Benchmarks]]
88 | Name = "semver"
89 | Benchmarks = "BenchmarkValidateVersionTildeFail"
90 |
91 | [[Benchmarks]]
92 | Name = "k8s_cache"
93 | Benchmarks = "Benchmark"
94 |
95 | [[Benchmarks]]
96 | Name = "k8s_workqueue"
97 | Benchmarks = "BenchmarkParallelizeUntil" # DelayingQueue is noisy
98 |
99 | [[Benchmarks]]
100 | Name = "uuid"
101 | Benchmarks = "Benchmark"
102 |
103 | [[Benchmarks]]
104 | Name = "gonum_topo"
105 | Benchmarks = "Benchmark(TarjanSCCGnp_1000_half|TarjanSCCGnp_10_tenth)"
106 |
107 | [[Benchmarks]]
108 | Name = "gonum_path"
109 | Benchmarks = "Benchmark(AStarUndirectedmallWorld_10_2_2_2_Heur|Dominators/nested_if_n256)"
110 |
111 | [[Benchmarks]]
112 | Name = "gonum_community"
113 | Benchmarks = "BenchmarkLouvainDirectedMultiplex"
114 |
115 | [[Benchmarks]]
116 | Name = "gonum_traverse"
117 | Benchmarks = "BenchmarkWalkAllBreadthFirstGnp_(10|1000)_tenth" # more difference by size than anything else
118 |
119 | [[Benchmarks]]
120 | Name = "capnproto2"
121 | Benchmarks = "Benchmark(TextMovementBetweenSegments|Growth_MultiSegment)"
122 |
123 | [[Benchmarks]]
124 | Name = "uber_zap"
125 | Benchmarks = "Benchmark"
126 |
127 | [[Benchmarks]]
128 | Name = "uber_tally"
129 | Benchmarks = "ScopeTaggedNoCachedSubscopes|HistogramAllocation"
130 |
131 | [[Benchmarks]]
132 | Name = "bindata"
133 | Benchmarks = "Benchmark"
134 |
135 | [[Benchmarks]]
136 | Name = "cespare_mph"
137 | Benchmarks = "BenchmarkBuild"
138 |
139 | # Used by InfluxDB and Prometheus
140 | [[Benchmarks]]
141 | Name = "cespare_xxhash"
142 | Benchmarks = "BenchmarkHashes/.*,direct,string,n=10MB"
143 |
144 | [[Benchmarks]]
145 | Name = "gtank_blake2s"
146 | Benchmarks = "BenchmarkHash8K"
147 |
148 | [[Benchmarks]]
149 | Name = "gtank_ed25519"
150 | Benchmarks = "Benchmark(IsOnCurve|ScalarMult)"
151 |
152 | [[Benchmarks]]
153 | Name = "ajstarks_deck_generate"
154 | Benchmarks = "Benchmark(Polygon|Arc)"
155 |
156 | [[Benchmarks]]
157 | Name = "benhoyt_goawk_1_18"
158 | Benchmarks = "BenchmarkR"
159 |
160 | [[Benchmarks]]
161 | Name = "ericlagergren_decimal"
162 | Benchmarks = "BenchmarkPi/foo=.*/prec=100"
163 |
164 | [[Benchmarks]]
165 | Name = "dustin_broadcast"
166 | Benchmarks = "Benchmark[^B]" #Brodcast is noisy
167 |
168 | [[Benchmarks]]
169 | Name = "dustin_humanize"
170 | Benchmarks = "BenchmarkParseBigBytes"
171 |
172 | [[Benchmarks]]
173 | Name = "bloom_bloom"
174 | Benchmarks = "Benchmark[SC]" # avoid "Estimated"
175 |
176 | [[Benchmarks]]
177 | Name = "kanzi"
178 | Benchmarks = "Benchmark(FPAQ|LZ|MTFT)$"
179 |
180 | [[Benchmarks]]
181 | Name = "commonmark_markdown"
182 | Benchmarks = "Benchmark(RenderSpec|RenderSpecBlackFriday2)"
183 |
184 |
--------------------------------------------------------------------------------