mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-06 09:55:40 +00:00
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:
+38
-31
@@ -3,6 +3,7 @@
|
|||||||
package router
|
package router
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"image"
|
"image"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@@ -452,37 +453,43 @@ 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
|
||||||
handlers := make([]event.Key, handlerCount)
|
const maxHandlerCount = 100
|
||||||
for i := 0; i < handlerCount; i++ {
|
for i := startingHandlerCount; i < maxHandlerCount; i *= 3 {
|
||||||
h := new(int)
|
handlerCount := i
|
||||||
*h = i
|
b.Run(fmt.Sprintf("%d-handlers", i), func(b *testing.B) {
|
||||||
handlers[i] = h
|
handlers := make([]event.Key, handlerCount)
|
||||||
}
|
for i := 0; i < handlerCount; i++ {
|
||||||
var ops op.Ops
|
h := new(int)
|
||||||
|
*h = i
|
||||||
|
handlers[i] = h
|
||||||
|
}
|
||||||
|
var ops op.Ops
|
||||||
|
|
||||||
for i := range handlers {
|
for i := range handlers {
|
||||||
pointer.Rect(image.Rectangle{
|
pointer.Rect(image.Rectangle{
|
||||||
Max: image.Point{
|
Max: image.Point{
|
||||||
X: 100,
|
X: 100,
|
||||||
Y: 100,
|
Y: 100,
|
||||||
},
|
},
|
||||||
}).Add(&ops)
|
}).Add(&ops)
|
||||||
pointer.InputOp{Key: handlers[i]}.Add(&ops)
|
pointer.InputOp{Key: handlers[i]}.Add(&ops)
|
||||||
}
|
}
|
||||||
var r Router
|
var r Router
|
||||||
r.Frame(&ops)
|
r.Frame(&ops)
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
r.Add(
|
r.Add(
|
||||||
pointer.Event{
|
pointer.Event{
|
||||||
Type: pointer.Move,
|
Type: pointer.Move,
|
||||||
Position: f32.Point{
|
Position: f32.Point{
|
||||||
X: 50,
|
X: 50,
|
||||||
Y: 50,
|
Y: 50,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user