bench_test.go 2.6 KB

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