go bench_test 源码
golang bench_test 代码
文件路径:/src/cmd/link/internal/benchmark/bench_test.go
// Copyright 2020 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package benchmark
import (
"testing"
)
func TestMakeBenchString(t *testing.T) {
tests := []struct {
have, want string
}{
{"foo", "BenchmarkFoo"},
{" foo ", "BenchmarkFoo"},
{"foo bar", "BenchmarkFooBar"},
}
for i, test := range tests {
if v := makeBenchString(test.have); test.want != v {
t.Errorf("test[%d] makeBenchString(%q) == %q, want %q", i, test.have, v, test.want)
}
}
}
func TestPProfFlag(t *testing.T) {
tests := []struct {
name string
want bool
}{
{"", false},
{"foo", true},
}
for i, test := range tests {
b := New(GC, test.name)
if v := b.shouldPProf(); test.want != v {
t.Errorf("test[%d] shouldPProf() == %v, want %v", i, v, test.want)
}
}
}
func TestPProfNames(t *testing.T) {
want := "foo_BenchmarkTest.cpuprof"
if v := makePProfFilename("foo", "test", "cpuprof"); v != want {
t.Errorf("makePProfFilename() == %q, want %q", v, want)
}
}
// Ensure that public APIs work with a nil Metrics object.
func TestNilBenchmarkObject(t *testing.T) {
var b *Metrics
b.Start("TEST")
b.Report(nil)
}
相关信息
相关文章
0
赞
热门推荐
-
2、 - 优质文章
-
3、 gate.io
-
7、 golang
-
9、 openharmony
-
10、 Vue中input框自动聚焦