@@ -51,6 +51,7 @@ func getBenchParams() []benchParam {
5151}
5252
5353func createBenchDir (b * testing.B , dir string ) {
54+ b .Helper ()
5455 if _ , err := os .Stat (dir ); os .IsNotExist (err ) {
5556 if err := os .Mkdir (dir , 0744 ); err != nil {
5657 b .Fatalf ("unable to create dir for benchmark: %v" , err )
@@ -59,6 +60,7 @@ func createBenchDir(b *testing.B, dir string) {
5960}
6061
6162func removeBenchDir (b * testing.B , dir string ) {
63+ b .Helper ()
6264 if err := os .RemoveAll (dir ); err != nil {
6365 b .Fatalf ("unable to delete dir for benchmark: %v" , err )
6466 }
@@ -72,10 +74,10 @@ func BenchmarkNewMmapQueue(b *testing.B) {
7274 }
7375 prevValue = param .arenaSize
7476
75- b .Run (fmt .Sprintf ("ArenaSize-%s " , param .arenaSizeString ), func (b * testing.B ) {
77+ b .Run (fmt .Sprintf ("ArenaSize-%v " , param .arenaSizeString ), func (b * testing.B ) {
7678 b .ReportAllocs ()
7779 b .StopTimer ()
78- for i := 0 ; i < b .N ; i ++ {
80+ for range b .N {
7981 dir := path .Join (os .TempDir (), "testdir" )
8082 createBenchDir (b , path .Join (os .TempDir (), "testdir" ))
8183
@@ -112,7 +114,7 @@ func BenchmarkEnqueue(b *testing.B) {
112114
113115 b .ReportAllocs ()
114116 b .ResetTimer ()
115- for i := 0 ; i < b .N ; i ++ {
117+ for range b .N {
116118 if err := bq .Enqueue (param .message ); err != nil {
117119 b .Fatalf ("unable to enqueue: %v" , err )
118120 }
@@ -144,7 +146,7 @@ func BenchmarkEnqueueString(b *testing.B) {
144146 message := string (param .message )
145147 b .ReportAllocs ()
146148 b .ResetTimer ()
147- for i := 0 ; i < b .N ; i ++ {
149+ for range b .N {
148150 if err := bq .EnqueueString (message ); err != nil {
149151 b .Fatalf ("unable to enqueue: %v" , err )
150152 }
@@ -173,15 +175,15 @@ func BenchmarkDequeue(b *testing.B) {
173175 b .Fatalf ("unable to create bigqueue: %v" , err )
174176 }
175177
176- for i := 0 ; i < b .N ; i ++ {
178+ for range b .N {
177179 if err := bq .Enqueue (param .message ); err != nil {
178180 b .Fatalf ("unable to enqueue: %v" , err )
179181 }
180182 }
181183
182184 b .ReportAllocs ()
183185 b .ResetTimer ()
184- for i := 0 ; i < b .N ; i ++ {
186+ for range b .N {
185187 if _ , err := bq .Dequeue (); err != nil {
186188 b .Fatalf ("unable to dequeue: %v" , err )
187189 }
@@ -211,15 +213,15 @@ func BenchmarkDequeueString(b *testing.B) {
211213 }
212214
213215 message := string (param .message )
214- for i := 0 ; i < b .N ; i ++ {
216+ for range b .N {
215217 if err := bq .EnqueueString (message ); err != nil {
216218 b .Fatalf ("unable to enqueue: %v" , err )
217219 }
218220 }
219221
220222 b .ReportAllocs ()
221223 b .ResetTimer ()
222- for i := 0 ; i < b .N ; i ++ {
224+ for range b .N {
223225 if _ , err := bq .DequeueString (); err != nil {
224226 b .Fatalf ("unable to dequeue: %v" , err )
225227 }
@@ -245,7 +247,7 @@ func BenchmarkStringDoubleCopy(b *testing.B) {
245247 }
246248
247249 data := "abcdefghijk"
248- for i := 0 ; i < b .N ; i ++ {
250+ for range b .N {
249251 if err := bq .Enqueue ([]byte (data )); err != nil {
250252 b .Fatalf ("error in enqueue :: %v" , err )
251253 }
@@ -263,7 +265,7 @@ func BenchmarkStringNoCopy(b *testing.B) {
263265 }
264266
265267 data := "abcdefghijk"
266- for i := 0 ; i < b .N ; i ++ {
268+ for range b .N {
267269 if err := bq .EnqueueString (data ); err != nil {
268270 b .Fatalf ("error in enqueue :: %v" , err )
269271 }
0 commit comments