Merge pull request #321 from glightfoot/improve-benchmarks

improve benchmark validity by not measuring startup costs
This commit is contained in:
Matthias Rampke 2020-07-02 22:19:44 +02:00 committed by GitHub
commit e43831c078
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 0 deletions

View file

@ -46,7 +46,14 @@ func benchmarkUDPListener(times int, b *testing.B) {
bytesInput[run*len(input)+i] = fmt.Sprintf("run%d%s", run, input[i])
}
}
// reset benchmark timer to not measure startup costs
b.ResetTimer()
for n := 0; n < b.N; n++ {
// pause benchmark timer for creating the chan and listener
b.StopTimer()
// there are more events than input lines, need bigger buffer
events := make(chan event.Events, len(bytesInput)*times*2)
@ -59,6 +66,9 @@ func benchmarkUDPListener(times int, b *testing.B) {
TagsReceived: tagsReceived,
}
// resume benchmark timer
b.StartTimer()
for i := 0; i < times; i++ {
for _, line := range bytesInput {
l.HandlePacket([]byte(line))
@ -154,8 +164,19 @@ mappings:
}
ex := exporter.NewExporter(testMapper, log.NewNopLogger(), eventsActions, eventsUnmapped, errorEventStats, eventStats, conflictingEventStats, metricsCount)
// reset benchmark timer to not measure startup costs
b.ResetTimer()
for i := 0; i < b.N; i++ {
// pause benchmark timer for creating the chan
b.StopTimer()
ec := make(chan event.Events, 1000)
// resume benchmark timer
b.StartTimer()
go func() {
for i := 0; i < 1000; i++ {
ec <- events

View file

@ -37,6 +37,9 @@ func benchmarkLineToEvents(times int, b *testing.B) {
}
logger := log.NewNopLogger()
// reset benchmark timer to not measure startup costs
b.ResetTimer()
for n := 0; n < b.N; n++ {
for i := 0; i < times; i++ {
for _, l := range input {