1// Copyright 2017 Unknwon 2// 3// Licensed under the Apache License, Version 2.0 (the "License"): you may 4// not use this file except in compliance with the License. You may obtain 5// 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, WITHOUT 11// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12// License for the specific language governing permissions and limitations 13// under the License. 14 15package ini_test 16 17import ( 18 "testing" 19 20 "gopkg.in/ini.v1" 21) 22 23func newTestFile(block bool) *ini.File { 24 c, _ := ini.Load([]byte(confData)) 25 c.BlockMode = block 26 return c 27} 28 29func Benchmark_Key_Value(b *testing.B) { 30 c := newTestFile(true) 31 for i := 0; i < b.N; i++ { 32 c.Section("").Key("NAME").Value() 33 } 34} 35 36func Benchmark_Key_Value_NonBlock(b *testing.B) { 37 c := newTestFile(false) 38 for i := 0; i < b.N; i++ { 39 c.Section("").Key("NAME").Value() 40 } 41} 42 43func Benchmark_Key_Value_ViaSection(b *testing.B) { 44 c := newTestFile(true) 45 sec := c.Section("") 46 for i := 0; i < b.N; i++ { 47 sec.Key("NAME").Value() 48 } 49} 50 51func Benchmark_Key_Value_ViaSection_NonBlock(b *testing.B) { 52 c := newTestFile(false) 53 sec := c.Section("") 54 for i := 0; i < b.N; i++ { 55 sec.Key("NAME").Value() 56 } 57} 58 59func Benchmark_Key_Value_Direct(b *testing.B) { 60 c := newTestFile(true) 61 key := c.Section("").Key("NAME") 62 for i := 0; i < b.N; i++ { 63 key.Value() 64 } 65} 66 67func Benchmark_Key_Value_Direct_NonBlock(b *testing.B) { 68 c := newTestFile(false) 69 key := c.Section("").Key("NAME") 70 for i := 0; i < b.N; i++ { 71 key.Value() 72 } 73} 74 75func Benchmark_Key_String(b *testing.B) { 76 c := newTestFile(true) 77 for i := 0; i < b.N; i++ { 78 _ = c.Section("").Key("NAME").String() 79 } 80} 81 82func Benchmark_Key_String_NonBlock(b *testing.B) { 83 c := newTestFile(false) 84 for i := 0; i < b.N; i++ { 85 _ = c.Section("").Key("NAME").String() 86 } 87} 88 89func Benchmark_Key_String_ViaSection(b *testing.B) { 90 c := newTestFile(true) 91 sec := c.Section("") 92 for i := 0; i < b.N; i++ { 93 _ = sec.Key("NAME").String() 94 } 95} 96 97func Benchmark_Key_String_ViaSection_NonBlock(b *testing.B) { 98 c := newTestFile(false) 99 sec := c.Section("") 100 for i := 0; i < b.N; i++ { 101 _ = sec.Key("NAME").String() 102 } 103} 104 105func Benchmark_Key_SetValue(b *testing.B) { 106 c := newTestFile(true) 107 for i := 0; i < b.N; i++ { 108 c.Section("").Key("NAME").SetValue("10") 109 } 110} 111 112func Benchmark_Key_SetValue_VisSection(b *testing.B) { 113 c := newTestFile(true) 114 sec := c.Section("") 115 for i := 0; i < b.N; i++ { 116 sec.Key("NAME").SetValue("10") 117 } 118} 119