Skip to content

Commit bb05b24

Browse files
committed
chore(example): add edge case where timer is stopped at end of benchmark
1 parent 2586530 commit bb05b24

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed

example/setup_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,25 @@ func BenchmarkWithoutStartupTraditional(b *testing.B) {
8989
time.Sleep(1 * time.Millisecond)
9090
}
9191
}
92+
93+
func BenchmarkWithStopTraditional(b *testing.B) {
94+
time.Sleep(2 * time.Millisecond)
95+
96+
b.ResetTimer()
97+
for i := 0; i < b.N; i++ {
98+
time.Sleep(1 * time.Millisecond)
99+
}
100+
101+
b.StopTimer()
102+
}
103+
104+
func BenchmarkWithStopModern(b *testing.B) {
105+
time.Sleep(2 * time.Millisecond)
106+
107+
b.ResetTimer()
108+
for b.Loop() {
109+
time.Sleep(1 * time.Millisecond)
110+
}
111+
112+
b.StopTimer()
113+
}

go-runner/src/builder/snapshots/codspeed_go_runner__builder__discovery__tests__discover_benchmarks@example.snap

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,22 @@ expression: packages
7878
"file_path": "setup_test.go",
7979
"is_external": false
8080
},
81+
{
82+
"name": "BenchmarkWithStopModern",
83+
"module_path": "example",
84+
"import_alias": "benchmarkwithstopmodern_9576953055782987076",
85+
"qualified_name": "benchmarkwithstopmodern_9576953055782987076.BenchmarkWithStopModern",
86+
"file_path": "setup_test.go",
87+
"is_external": false
88+
},
89+
{
90+
"name": "BenchmarkWithStopTraditional",
91+
"module_path": "example",
92+
"import_alias": "benchmarkwithstoptraditional_9576953055782987076",
93+
"qualified_name": "benchmarkwithstoptraditional_9576953055782987076.BenchmarkWithStopTraditional",
94+
"file_path": "setup_test.go",
95+
"is_external": false
96+
},
8197
{
8298
"name": "BenchmarkWithoutStartupModern",
8399
"module_path": "example",

go-runner/src/snapshots/codspeed_go_runner__integration_tests__assert_results_snapshots@example.snap

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,17 @@ expression: results
180180
},
181181
"stats": "[stats]"
182182
},
183+
{
184+
"name": "BenchmarkLargeSetupInLoop",
185+
"uri": "example/setup_test.go::BenchmarkLargeSetupInLoop",
186+
"config": {
187+
"warmup_time_ns": null,
188+
"min_round_time_ns": null,
189+
"max_time_ns": null,
190+
"max_rounds": null
191+
},
192+
"stats": "[stats]"
193+
},
183194
{
184195
"name": "BenchmarkWithOutlierMeasurementModern",
185196
"uri": "example/setup_test.go::BenchmarkWithOutlierMeasurementModern",
@@ -202,6 +213,28 @@ expression: results
202213
},
203214
"stats": "[stats]"
204215
},
216+
{
217+
"name": "BenchmarkWithStopModern",
218+
"uri": "example/setup_test.go::BenchmarkWithStopModern",
219+
"config": {
220+
"warmup_time_ns": null,
221+
"min_round_time_ns": null,
222+
"max_time_ns": null,
223+
"max_rounds": null
224+
},
225+
"stats": "[stats]"
226+
},
227+
{
228+
"name": "BenchmarkWithStopTraditional",
229+
"uri": "example/setup_test.go::BenchmarkWithStopTraditional",
230+
"config": {
231+
"warmup_time_ns": null,
232+
"min_round_time_ns": null,
233+
"max_time_ns": null,
234+
"max_rounds": null
235+
},
236+
"stats": "[stats]"
237+
},
205238
{
206239
"name": "BenchmarkWithoutStartupModern",
207240
"uri": "example/setup_test.go::BenchmarkWithoutStartupModern",

0 commit comments

Comments
 (0)