Report average frame time.

This commit is contained in:
Greg 2019-10-10 10:37:50 -04:00
parent 07ba8917e0
commit 93e199bd33
2 changed files with 30 additions and 2 deletions

View File

@ -39,6 +39,8 @@ func loop(w *app.Window) error {
q := w.Queue()
face := faces.For(regular, ui.Sp(16))
lst := layout.List{Axis: layout.Vertical}
times := make([]int64, 100)
timesIndex := 0
for {
e := <-w.Events()
switch e := e.(type) {
@ -54,7 +56,19 @@ func loop(w *app.Window) error {
}
lst.Layout()
w.Update(ops)
log.Printf("Frame time: %s\n", time.Since(stime))
dur := time.Since(stime)
//fmt.Printf("Frame time: %s\n", dur)
times[timesIndex] = dur.Nanoseconds()
timesIndex++
if timesIndex == 100 {
timesIndex = 0
var avg int64
for i := 0; i < 100; i++ {
avg += times[i]
}
avg = avg / 100000
fmt.Printf("Average frame time: %d microseconds\n", avg)
}
}
}
}

View File

@ -37,6 +37,8 @@ func loop(w *app.Window) error {
family := &shape.Family{Regular: regular}
gtx := &layout.Context{Queue: w.Queue()}
lst := &layout.List{Axis: layout.Vertical}
times := make([]int64, 100)
timesIndex := 0
for {
e := <-w.Events()
switch e := e.(type) {
@ -51,7 +53,19 @@ func loop(w *app.Window) error {
})
}
w.Update(gtx.Ops)
log.Printf("Frame time: %s\n", time.Since(stime))
dur := time.Since(stime)
//fmt.Printf("Frame time: %s\n", dur)
times[timesIndex] = dur.Nanoseconds()
timesIndex++
if timesIndex == 100 {
timesIndex = 0
var avg int64
for i := 0; i < 100; i++ {
avg += times[i]
}
avg = avg / 100000
fmt.Printf("Average frame time: %d microseconds\n", avg)
}
}
}
}