io/router: improve areaOp methods performance

name             old time/op  new time/op  delta
AreaOp_Decode-8  10.5ns ± 2%   6.2ns ± 3%  -41.50%  (p=0.000 n=10+10)
AreaOp_Hit-8     4.44ns ± 4%  3.57ns ± 2%  -19.59%  (p=0.000 n=10+10)

Signed-off-by: pierre <pierre.curto@gmail.com>
This commit is contained in:
pierre
2021-02-24 12:29:22 +01:00
committed by Elias Naur
parent 212f7809cb
commit cfb16083a2
2 changed files with 36 additions and 19 deletions
+19
View File
@@ -651,3 +651,22 @@ func BenchmarkRouterAdd(b *testing.B) {
})
}
}
var benchAreaOp areaOp
func BenchmarkAreaOp_Decode(b *testing.B) {
ops := new(op.Ops)
pointer.Rect(image.Rectangle{Max: image.Pt(100, 100)}).Add(ops)
for i := 0; i < b.N; i++ {
benchAreaOp.Decode(ops.Data())
}
}
func BenchmarkAreaOp_Hit(b *testing.B) {
ops := new(op.Ops)
pointer.Rect(image.Rectangle{Max: image.Pt(100, 100)}).Add(ops)
benchAreaOp.Decode(ops.Data())
for i := 0; i < b.N; i++ {
benchAreaOp.Hit(f32.Pt(50, 50))
}
}