| 1 |
// Copyright 2018 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 trace_test |
| 6 |
|
| 7 |
import ( |
| 8 |
"context" |
| 9 |
"io" |
| 10 |
. "runtime/trace" |
| 11 |
"testing" |
| 12 |
) |
| 13 |
|
| 14 |
func BenchmarkStartRegion(b *testing.B) { |
| 15 |
b.ReportAllocs() |
| 16 |
ctx, task := NewTask(context.Background(), "benchmark") |
| 17 |
defer task.End() |
| 18 |
|
| 19 |
b.RunParallel(func(pb *testing.PB) { |
| 20 |
for pb.Next() { |
| 21 |
StartRegion(ctx, "region").End() |
| 22 |
} |
| 23 |
}) |
| 24 |
} |
| 25 |
|
| 26 |
func BenchmarkNewTask(b *testing.B) { |
| 27 |
b.ReportAllocs() |
| 28 |
pctx, task := NewTask(context.Background(), "benchmark") |
| 29 |
defer task.End() |
| 30 |
|
| 31 |
b.RunParallel(func(pb *testing.PB) { |
| 32 |
for pb.Next() { |
| 33 |
_, task := NewTask(pctx, "task") |
| 34 |
task.End() |
| 35 |
} |
| 36 |
}) |
| 37 |
} |
| 38 |
|
| 39 |
func BenchmarkLog(b *testing.B) { |
| 40 |
b.ReportAllocs() |
| 41 |
|
| 42 |
Start(io.Discard) |
| 43 |
defer Stop() |
| 44 |
|
| 45 |
ctx := context.Background() |
| 46 |
for b.Loop() { |
| 47 |
Log(ctx, "", "") |
| 48 |
} |
| 49 |
} |