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 5package trace_test 6 7import ( 8 "context" 9 . "runtime/trace" 10 "testing" 11) 12 13func BenchmarkStartRegion(b *testing.B) { 14 b.ReportAllocs() 15 ctx, task := NewTask(context.Background(), "benchmark") 16 defer task.End() 17 18 b.RunParallel(func(pb *testing.PB) { 19 for pb.Next() { 20 StartRegion(ctx, "region").End() 21 } 22 }) 23} 24 25func BenchmarkNewTask(b *testing.B) { 26 b.ReportAllocs() 27 pctx, task := NewTask(context.Background(), "benchmark") 28 defer task.End() 29 30 b.RunParallel(func(pb *testing.PB) { 31 for pb.Next() { 32 _, task := NewTask(pctx, "task") 33 task.End() 34 } 35 }) 36} 37