io/router: improve benchmark by trying multiple sizes

This commit improves the usefulness of the benchmark by automatically
measuring event processing times with a range of values for the complexity
of the UI.

Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
This commit is contained in:
Chris Waldon
2020-05-06 22:23:12 -04:00
committed by Elias Naur
parent b2f1776670
commit c1f0f9b5c7
+8 -1
View File
@@ -3,6 +3,7 @@
package router package router
import ( import (
"fmt"
"image" "image"
"testing" "testing"
@@ -452,7 +453,11 @@ func BenchmarkRouterAdd(b *testing.B) {
// evaluate performance for. Typical values for the example applications // evaluate performance for. Typical values for the example applications
// are 1-3, though checking highers values helps evaluate performance for // are 1-3, though checking highers values helps evaluate performance for
// more complex applications. // more complex applications.
const handlerCount = 3 const startingHandlerCount = 3
const maxHandlerCount = 100
for i := startingHandlerCount; i < maxHandlerCount; i *= 3 {
handlerCount := i
b.Run(fmt.Sprintf("%d-handlers", i), func(b *testing.B) {
handlers := make([]event.Key, handlerCount) handlers := make([]event.Key, handlerCount)
for i := 0; i < handlerCount; i++ { for i := 0; i < handlerCount; i++ {
h := new(int) h := new(int)
@@ -485,4 +490,6 @@ func BenchmarkRouterAdd(b *testing.B) {
}, },
) )
} }
})
}
} }