Last active
November 27, 2021 18:58
-
-
Save ginokent/762cefddc1ebcd5ae8f5748209f0f2f1 to your computer and use it in GitHub Desktop.
Go benchmark ベンチマーク 覚書
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 前準備 | |
mkdir -p /tmp/benchmark | |
cd /tmp/benchmark | |
# ベンチマークファイル作成 | |
tee /tmp/benchmark/benchmark_test.go <<"EOF" | |
package benchmark_test | |
import ( | |
"strconv" | |
"testing" | |
) | |
func BenchmarkAppendQuote(b *testing.B) { | |
s := []byte{} | |
b.ResetTimer() | |
for i := 0; i < b.N; i++ { | |
s = strconv.AppendQuote(s, `\"a\"`) | |
} | |
} | |
EOF | |
# ベンチマーク走らせる | |
go test -bench . -benchmem -test.run=none -test.benchtime=1000ms | |
# alloc と free のトレースを見る | |
go test -c | |
GODEBUG=allocfreetrace=1 ./"$(basename "${PWD}")".test -test.run=none -test.bench=BenchmarkAppendQuote -test.benchtime=1ms > trace.log 2>&1 | |
# EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment