Skip to content

Commit 4ddd8f1

Browse files
committed
chore(example): add more test cases to handle setup scenarios
1 parent 0f118b3 commit 4ddd8f1

3 files changed

Lines changed: 106 additions & 2 deletions

File tree

example/setup_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package example
33
import (
44
"runtime"
55
"testing"
6+
"time"
67
)
78

89
func BenchmarkLargeSetup(b *testing.B) {
@@ -50,3 +51,41 @@ func BenchmarkLargeSetupInLoop(b *testing.B) {
5051
}
5152
runtime.KeepAlive(result)
5253
}
54+
55+
func BenchmarkWithOutlierMeasurementTraditional(b *testing.B) {
56+
b.ResetTimer()
57+
for i := 0; i < b.N; i++ {
58+
b.StopTimer()
59+
time.Sleep(10 * time.Millisecond)
60+
b.StartTimer()
61+
62+
time.Sleep(1 * time.Millisecond)
63+
}
64+
}
65+
66+
func BenchmarkWithOutlierMeasurementModern(b *testing.B) {
67+
b.ResetTimer()
68+
for b.Loop() {
69+
b.StopTimer()
70+
time.Sleep(10 * time.Millisecond)
71+
b.StartTimer()
72+
73+
time.Sleep(1 * time.Millisecond)
74+
}
75+
}
76+
77+
func BenchmarkWithoutStartupModern(b *testing.B) {
78+
time.Sleep(10 * time.Millisecond)
79+
b.ResetTimer()
80+
for b.Loop() {
81+
time.Sleep(1 * time.Millisecond)
82+
}
83+
}
84+
85+
func BenchmarkWithoutStartupTraditional(b *testing.B) {
86+
time.Sleep(10 * time.Millisecond)
87+
b.ResetTimer()
88+
for i := 0; i < b.N; i++ {
89+
time.Sleep(1 * time.Millisecond)
90+
}
91+
}

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,38 @@ expression: packages
6161
"qualified_name": "benchmarklargesetupinloop_9576953055782987076.BenchmarkLargeSetupInLoop",
6262
"file_path": "setup_test.go",
6363
"is_external": false
64+
},
65+
{
66+
"name": "BenchmarkWithOutlierMeasurementModern",
67+
"module_path": "example",
68+
"import_alias": "benchmarkwithoutliermeasurementmodern_9576953055782987076",
69+
"qualified_name": "benchmarkwithoutliermeasurementmodern_9576953055782987076.BenchmarkWithOutlierMeasurementModern",
70+
"file_path": "setup_test.go",
71+
"is_external": false
72+
},
73+
{
74+
"name": "BenchmarkWithOutlierMeasurementTraditional",
75+
"module_path": "example",
76+
"import_alias": "benchmarkwithoutliermeasurementtraditional_9576953055782987076",
77+
"qualified_name": "benchmarkwithoutliermeasurementtraditional_9576953055782987076.BenchmarkWithOutlierMeasurementTraditional",
78+
"file_path": "setup_test.go",
79+
"is_external": false
80+
},
81+
{
82+
"name": "BenchmarkWithoutStartupModern",
83+
"module_path": "example",
84+
"import_alias": "benchmarkwithoutstartupmodern_9576953055782987076",
85+
"qualified_name": "benchmarkwithoutstartupmodern_9576953055782987076.BenchmarkWithoutStartupModern",
86+
"file_path": "setup_test.go",
87+
"is_external": false
88+
},
89+
{
90+
"name": "BenchmarkWithoutStartupTraditional",
91+
"module_path": "example",
92+
"import_alias": "benchmarkwithoutstartuptraditional_9576953055782987076",
93+
"qualified_name": "benchmarkwithoutstartuptraditional_9576953055782987076.BenchmarkWithoutStartupTraditional",
94+
"file_path": "setup_test.go",
95+
"is_external": false
6496
}
6597
]
6698
},

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

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,41 @@ expression: results
181181
"stats": "[stats]"
182182
},
183183
{
184-
"name": "BenchmarkLargeSetupInLoop",
185-
"uri": "example/setup_test.go::BenchmarkLargeSetupInLoop",
184+
"name": "BenchmarkWithOutlierMeasurementModern",
185+
"uri": "example/setup_test.go::BenchmarkWithOutlierMeasurementModern",
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+
},
194+
{
195+
"name": "BenchmarkWithOutlierMeasurementTraditional",
196+
"uri": "example/setup_test.go::BenchmarkWithOutlierMeasurementTraditional",
197+
"config": {
198+
"warmup_time_ns": null,
199+
"min_round_time_ns": null,
200+
"max_time_ns": null,
201+
"max_rounds": null
202+
},
203+
"stats": "[stats]"
204+
},
205+
{
206+
"name": "BenchmarkWithoutStartupModern",
207+
"uri": "example/setup_test.go::BenchmarkWithoutStartupModern",
208+
"config": {
209+
"warmup_time_ns": null,
210+
"min_round_time_ns": null,
211+
"max_time_ns": null,
212+
"max_rounds": null
213+
},
214+
"stats": "[stats]"
215+
},
216+
{
217+
"name": "BenchmarkWithoutStartupTraditional",
218+
"uri": "example/setup_test.go::BenchmarkWithoutStartupTraditional",
186219
"config": {
187220
"warmup_time_ns": null,
188221
"min_round_time_ns": null,

0 commit comments

Comments
 (0)