You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: testing/testing/benchmark.go
+67-14Lines changed: 67 additions & 14 deletions
Original file line number
Diff line number
Diff line change
@@ -90,6 +90,10 @@ type codspeed struct {
90
90
91
91
codspeedTimePerRoundNs []time.Duration
92
92
codspeedItersPerRound []int64
93
+
94
+
startTimestampuint64
95
+
startTimestamps []uint64
96
+
stopTimestamps []uint64
93
97
}
94
98
95
99
// B is a type passed to [Benchmark] functions to manage benchmark
@@ -150,7 +154,7 @@ type B struct {
150
154
// StartTimer starts timing a test. This function is called automatically
151
155
// before a benchmark starts, but it can also be used to resume timing after
152
156
// a call to [B.StopTimer].
153
-
func (b*B) StartTimer() {
157
+
func (b*B) StartTimerWithoutMarker() {
154
158
if!b.timerOn {
155
159
// runtime.ReadMemStats(&memStats)
156
160
// b.startAllocs = memStats.Mallocs
@@ -161,9 +165,19 @@ func (b *B) StartTimer() {
161
165
}
162
166
}
163
167
168
+
func (b*B) StartTimer() {
169
+
timerOn:=b.timerOn
170
+
171
+
b.StartTimerWithoutMarker()
172
+
173
+
if!timerOn {
174
+
b.startTimestamp=capi.CurrentTimestamp()
175
+
}
176
+
}
177
+
164
178
// StopTimer stops timing a test. This can be used to pause the timer
165
179
// while performing steps that you don't want to measure.
166
-
func (b*B) StopTimer() {
180
+
func (b*B) StopTimerWithoutMarker() {
167
181
ifb.timerOn {
168
182
timeSinceStart:=highPrecisionTimeSince(b.start)
169
183
b.duration+=timeSinceStart
@@ -183,6 +197,25 @@ func (b *B) StopTimer() {
183
197
}
184
198
}
185
199
200
+
func (b*B) StopTimer() {
201
+
endTimestamp:=capi.CurrentTimestamp()
202
+
timerOn:=b.timerOn
203
+
204
+
b.StopTimerWithoutMarker()
205
+
206
+
iftimerOn {
207
+
ifb.startTimestamp>=endTimestamp {
208
+
// This should never happen, unless we have a bug in the timer logic.
209
+
panic(fmt.Sprintf("Invalid benchmark timestamps: start timestamp (%d) is greater than or equal to end timestamp (%d)", b.startTimestamp, endTimestamp))
0 commit comments