gioui.org@v0.6.1-0.20240506124620-7a9ce51988ce/layout/stack_test.go (about) 1 // SPDX-License-Identifier: Unlicense OR MIT 2 3 package layout 4 5 import ( 6 "image" 7 "testing" 8 9 "gioui.org/op" 10 ) 11 12 func BenchmarkStack(b *testing.B) { 13 gtx := Context{ 14 Ops: new(op.Ops), 15 Constraints: Constraints{ 16 Max: image.Point{X: 100, Y: 100}, 17 }, 18 } 19 b.ReportAllocs() 20 b.ResetTimer() 21 22 for i := 0; i < b.N; i++ { 23 gtx.Ops.Reset() 24 25 Stack{}.Layout(gtx, 26 Expanded(emptyWidget{ 27 Size: image.Point{X: 60, Y: 60}, 28 }.Layout), 29 Stacked(emptyWidget{ 30 Size: image.Point{X: 30, Y: 30}, 31 }.Layout), 32 ) 33 } 34 } 35 36 func BenchmarkBackground(b *testing.B) { 37 gtx := Context{ 38 Ops: new(op.Ops), 39 Constraints: Constraints{ 40 Max: image.Point{X: 100, Y: 100}, 41 }, 42 } 43 b.ReportAllocs() 44 b.ResetTimer() 45 46 for i := 0; i < b.N; i++ { 47 gtx.Ops.Reset() 48 49 Background{}.Layout(gtx, 50 emptyWidget{ 51 Size: image.Point{X: 60, Y: 60}, 52 }.Layout, 53 emptyWidget{ 54 Size: image.Point{X: 30, Y: 30}, 55 }.Layout, 56 ) 57 } 58 } 59 60 type emptyWidget struct { 61 Size image.Point 62 } 63 64 func (w emptyWidget) Layout(gtx Context) Dimensions { 65 return Dimensions{Size: w.Size} 66 }