github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/util/stringarena/arena_test.go (about) 1 // Copyright 2018 The Cockroach Authors. 2 // 3 // Use of this software is governed by the Business Source License 4 // included in the file licenses/BSL.txt. 5 // 6 // As of the Change Date specified in that file, in accordance with 7 // the Business Source License, use of this software will be governed 8 // by the Apache License, Version 2.0, included in the file 9 // licenses/APL.txt. 10 11 package stringarena 12 13 import ( 14 "context" 15 "fmt" 16 "testing" 17 ) 18 19 func BenchmarkStringArena(b *testing.B) { 20 const count = 1024 21 vals := make([][]byte, count) 22 for i := range vals { 23 vals[i] = []byte(fmt.Sprint(i)) 24 } 25 26 b.Run("arena", func(b *testing.B) { 27 a := Make(nil /* acc */) 28 m := make([]string, count) 29 30 for i := 0; i < b.N; i++ { 31 j := i % count 32 s, err := a.AllocBytes(context.Background(), vals[j]) 33 if err != nil { 34 b.Fatal(err) 35 } 36 m[j] = s 37 } 38 }) 39 40 b.Run("noarena", func(b *testing.B) { 41 m := make([]string, count) 42 43 for i := 0; i < b.N; i++ { 44 j := i % count 45 m[j] = string(vals[j]) 46 } 47 }) 48 }