harness.go 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. // Copyright (C) MongoDB, Inc. 2017-present.
  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 http://www.apache.org/licenses/LICENSE-2.0
  6. package benchmark // import "go.mongodb.org/mongo-driver/benchmark"
  7. import (
  8. "context"
  9. "testing"
  10. "time"
  11. "github.com/stretchr/testify/require"
  12. )
  13. const (
  14. five = 5
  15. ten = 2 * five
  16. hundred = ten * ten
  17. thousand = ten * hundred
  18. tenThousand = ten * thousand
  19. hundredThousand = hundred * thousand
  20. million = hundred * hundredThousand
  21. halfMillion = five * hundredThousand
  22. ExecutionTimeout = five * time.Minute
  23. StandardRuntime = time.Minute
  24. MinimumRuntime = five * time.Second
  25. MinIterations = hundred
  26. )
  27. type BenchCase func(context.Context, TimerManager, int) error
  28. type BenchFunction func(*testing.B)
  29. func WrapCase(bench BenchCase) BenchFunction {
  30. name := getName(bench)
  31. return func(b *testing.B) {
  32. ctx := context.Background()
  33. b.ResetTimer()
  34. err := bench(ctx, b, b.N)
  35. require.NoError(b, err, "case='%s'", name)
  36. }
  37. }
  38. func getAllCases() []*CaseDefinition {
  39. return []*CaseDefinition{
  40. {
  41. Bench: CanaryIncCase,
  42. Count: million,
  43. Size: -1,
  44. Runtime: MinimumRuntime,
  45. RequiredIterations: ten,
  46. },
  47. {
  48. Bench: GlobalCanaryIncCase,
  49. Count: million,
  50. Size: -1,
  51. Runtime: MinimumRuntime,
  52. RequiredIterations: ten,
  53. },
  54. {
  55. Bench: BSONFlatDocumentEncoding,
  56. Count: tenThousand,
  57. Size: 75310000,
  58. Runtime: StandardRuntime,
  59. },
  60. {
  61. Bench: BSONFlatDocumentDecodingLazy,
  62. Count: tenThousand,
  63. Size: 75310000,
  64. Runtime: StandardRuntime,
  65. },
  66. {
  67. Bench: BSONFlatDocumentDecoding,
  68. Count: tenThousand,
  69. Size: 75310000,
  70. Runtime: StandardRuntime,
  71. },
  72. {
  73. Bench: BSONDeepDocumentEncoding,
  74. Count: tenThousand,
  75. Size: 19640000,
  76. Runtime: StandardRuntime,
  77. },
  78. {
  79. Bench: BSONDeepDocumentDecodingLazy,
  80. Count: tenThousand,
  81. Size: 19640000,
  82. Runtime: StandardRuntime,
  83. },
  84. {
  85. Bench: BSONDeepDocumentDecoding,
  86. Count: tenThousand,
  87. Size: 19640000,
  88. Runtime: StandardRuntime,
  89. },
  90. // {
  91. // Bench: BSONFullDocumentEncoding,
  92. // Count: tenThousand,
  93. // Size: 57340000,
  94. // Runtime: StandardRuntime,
  95. // },
  96. // {
  97. // Bench: BSONFullDocumentDecodingLazy,
  98. // Count: tenThousand,
  99. // Size: 57340000,
  100. // Runtime: StandardRuntime,
  101. // },
  102. // {
  103. // Bench: BSONFullDocumentDecoding,
  104. // Count: tenThousand,
  105. // Size: 57340000,
  106. // Runtime: StandardRuntime,
  107. // },
  108. // {
  109. // Bench: BSONFullReaderDecoding,
  110. // Count: tenThousand,
  111. // Size: 57340000,
  112. // Runtime: StandardRuntime,
  113. // },
  114. {
  115. Bench: BSONFlatMapDecoding,
  116. Count: tenThousand,
  117. Size: 75310000,
  118. Runtime: StandardRuntime,
  119. },
  120. {
  121. Bench: BSONFlatMapEncoding,
  122. Count: tenThousand,
  123. Size: 75310000,
  124. Runtime: StandardRuntime,
  125. },
  126. {
  127. Bench: BSONDeepMapDecoding,
  128. Count: tenThousand,
  129. Size: 19640000,
  130. Runtime: StandardRuntime,
  131. },
  132. {
  133. Bench: BSONDeepMapEncoding,
  134. Count: tenThousand,
  135. Size: 19640000,
  136. Runtime: StandardRuntime,
  137. },
  138. // {
  139. // Bench: BSONFullMapDecoding,
  140. // Count: tenThousand,
  141. // Size: 57340000,
  142. // Runtime: StandardRuntime,
  143. // },
  144. // {
  145. // Bench: BSONFullMapEncoding,
  146. // Count: tenThousand,
  147. // Size: 57340000,
  148. // Runtime: StandardRuntime,
  149. // },
  150. {
  151. Bench: BSONFlatStructDecoding,
  152. Count: tenThousand,
  153. Size: 75310000,
  154. Runtime: StandardRuntime,
  155. },
  156. {
  157. Bench: BSONFlatStructTagsDecoding,
  158. Count: tenThousand,
  159. Size: 75310000,
  160. Runtime: StandardRuntime,
  161. },
  162. {
  163. Bench: BSONFlatStructEncoding,
  164. Count: tenThousand,
  165. Size: 75310000,
  166. Runtime: StandardRuntime,
  167. },
  168. {
  169. Bench: BSONFlatStructTagsEncoding,
  170. Count: tenThousand,
  171. Size: 75310000,
  172. Runtime: StandardRuntime,
  173. },
  174. {
  175. Bench: SingleRunCommand,
  176. Count: tenThousand,
  177. Size: 160000,
  178. Runtime: StandardRuntime,
  179. },
  180. {
  181. Bench: SingleFindOneByID,
  182. Count: tenThousand,
  183. Size: 16220000,
  184. Runtime: StandardRuntime,
  185. },
  186. {
  187. Bench: SingleInsertSmallDocument,
  188. Count: tenThousand,
  189. Size: 2750000,
  190. Runtime: StandardRuntime,
  191. },
  192. {
  193. Bench: SingleInsertLargeDocument,
  194. Count: ten,
  195. Size: 27310890,
  196. Runtime: StandardRuntime,
  197. },
  198. {
  199. Bench: MultiFindMany,
  200. Count: tenThousand,
  201. Size: 16220000,
  202. Runtime: StandardRuntime,
  203. },
  204. {
  205. Bench: MultiInsertSmallDocument,
  206. Count: tenThousand,
  207. Size: 2750000,
  208. Runtime: StandardRuntime,
  209. },
  210. {
  211. Bench: MultiInsertLargeDocument,
  212. Count: ten,
  213. Size: 27310890,
  214. Runtime: StandardRuntime,
  215. RequiredIterations: tenThousand,
  216. },
  217. }
  218. }