jkvatne / gio-v

Widgets for gio
Other
31 stars 5 forks source link

An easy benchmark to add: #3

Open egonelbre opened 2 years ago

egonelbre commented 2 years ago

Here's an easy benchmark to see the impact of the Layout. Making forks etc. is slightly annoying, so this is a faster way to do it :D.

package main

import (
    "gio-v/wid"
    "image"
    "testing"

    "gioui.org/font/gofont"
    "gioui.org/io/router"
    "gioui.org/io/system"
    "gioui.org/layout"
    "gioui.org/op"
)

func BenchmarkLayout(b *testing.B) {
    makePersons()
    currentTheme = wid.NewTheme(gofont.Collection(), 14, wid.MaterialDesignLight)
    setup()

    b.ResetTimer()
    b.ReportAllocs()

    var ops op.Ops
    var r router.Router
    for i := 0; i < b.N; i++ {
        gtx := layout.NewContext(&ops, system.FrameEvent{
            Size: image.Point{
                X: 1024,
                Y: 1024,
            },
            Queue: &r,
        })
        wid.Root(gtx)
    }
}