...

Source file src/gopkg.in/ini.v1/bench_test.go

Documentation: gopkg.in/ini.v1

     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  
    15  package ini
    16  
    17  import (
    18  	"testing"
    19  )
    20  
    21  func newTestFile(block bool) *File {
    22  	c, _ := Load([]byte(confData))
    23  	c.BlockMode = block
    24  	return c
    25  }
    26  
    27  func Benchmark_Key_Value(b *testing.B) {
    28  	c := newTestFile(true)
    29  	for i := 0; i < b.N; i++ {
    30  		c.Section("").Key("NAME").Value()
    31  	}
    32  }
    33  
    34  func Benchmark_Key_Value_NonBlock(b *testing.B) {
    35  	c := newTestFile(false)
    36  	for i := 0; i < b.N; i++ {
    37  		c.Section("").Key("NAME").Value()
    38  	}
    39  }
    40  
    41  func Benchmark_Key_Value_ViaSection(b *testing.B) {
    42  	c := newTestFile(true)
    43  	sec := c.Section("")
    44  	for i := 0; i < b.N; i++ {
    45  		sec.Key("NAME").Value()
    46  	}
    47  }
    48  
    49  func Benchmark_Key_Value_ViaSection_NonBlock(b *testing.B) {
    50  	c := newTestFile(false)
    51  	sec := c.Section("")
    52  	for i := 0; i < b.N; i++ {
    53  		sec.Key("NAME").Value()
    54  	}
    55  }
    56  
    57  func Benchmark_Key_Value_Direct(b *testing.B) {
    58  	c := newTestFile(true)
    59  	key := c.Section("").Key("NAME")
    60  	for i := 0; i < b.N; i++ {
    61  		key.Value()
    62  	}
    63  }
    64  
    65  func Benchmark_Key_Value_Direct_NonBlock(b *testing.B) {
    66  	c := newTestFile(false)
    67  	key := c.Section("").Key("NAME")
    68  	for i := 0; i < b.N; i++ {
    69  		key.Value()
    70  	}
    71  }
    72  
    73  func Benchmark_Key_String(b *testing.B) {
    74  	c := newTestFile(true)
    75  	for i := 0; i < b.N; i++ {
    76  		_ = c.Section("").Key("NAME").String()
    77  	}
    78  }
    79  
    80  func Benchmark_Key_String_NonBlock(b *testing.B) {
    81  	c := newTestFile(false)
    82  	for i := 0; i < b.N; i++ {
    83  		_ = c.Section("").Key("NAME").String()
    84  	}
    85  }
    86  
    87  func Benchmark_Key_String_ViaSection(b *testing.B) {
    88  	c := newTestFile(true)
    89  	sec := c.Section("")
    90  	for i := 0; i < b.N; i++ {
    91  		_ = sec.Key("NAME").String()
    92  	}
    93  }
    94  
    95  func Benchmark_Key_String_ViaSection_NonBlock(b *testing.B) {
    96  	c := newTestFile(false)
    97  	sec := c.Section("")
    98  	for i := 0; i < b.N; i++ {
    99  		_ = sec.Key("NAME").String()
   100  	}
   101  }
   102  
   103  func Benchmark_Key_SetValue(b *testing.B) {
   104  	c := newTestFile(true)
   105  	for i := 0; i < b.N; i++ {
   106  		c.Section("").Key("NAME").SetValue("10")
   107  	}
   108  }
   109  
   110  func Benchmark_Key_SetValue_VisSection(b *testing.B) {
   111  	c := newTestFile(true)
   112  	sec := c.Section("")
   113  	for i := 0; i < b.N; i++ {
   114  		sec.Key("NAME").SetValue("10")
   115  	}
   116  }
   117  

View as plain text