1// Copyright (c) 2019 The Jaeger Authors. 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15package jaeger 16 17import "testing" 18 19func BenchmarkSpanAllocator(b *testing.B) { 20 b.ResetTimer() 21 b.ReportAllocs() 22 23 b.Run("SyncPool", func(b *testing.B) { 24 benchSpanAllocator(newSyncPollSpanAllocator(), b) 25 }) 26 27 b.Run("Simple", func(b *testing.B) { 28 benchSpanAllocator(simpleSpanAllocator{}, b) 29 }) 30} 31 32func benchSpanAllocator(allocator SpanAllocator, b *testing.B) { 33 b.RunParallel(func(pb *testing.PB) { 34 queue := make(chan *Span, 1000) 35 cancel := make(chan bool, 1) 36 go func() { 37 for span := range queue { 38 allocator.Put(span) 39 } 40 cancel <- true 41 }() 42 for pb.Next() { 43 queue <- allocator.Get() 44 } 45 close(queue) 46 <-cancel 47 }) 48} 49