#!/usr/bin/env bash
set -euo pipefail
export TZ=UTC
out=${1:-out}
mkdir -p "$out"
{ go version; go env GOOS GOARCH CGO_ENABLED; grep -m1 'model name' /proc/cpuinfo; } > "$out/environment.txt"
go test -v . > "$out/test.txt"
go test -race . > "$out/race.txt"
go vet . > "$out/vet.txt"
go test -run='^$' -bench='Benchmark(Slice|Builder)$' -benchmem -benchtime=100ms -count=10 -cpu=1 > "$out/bench.txt"
go test -run='^$' -bench='^BenchmarkHot$' -pgo=off -benchtime=500ms -cpu=1 -cpuprofile="$out/train.pprof" -o "$out/train.test" > "$out/train.txt"
go tool pprof -top "$out/train.test" "$out/train.pprof" > "$out/train-top.txt"
go test -pgo="$PWD/$out/train.pprof" . > "$out/pgo-test.txt"
go test -c -pgo="$PWD/$out/train.pprof" -o "$out/pgo.test" .
go test -gcflags='-m=2' -run='^$' . > "$out/escape-stdout.txt" 2> "$out/escape.txt"
