Report average frame time.
This commit is contained in:
parent
07ba8917e0
commit
93e199bd33
16
fast/main.go
16
fast/main.go
|
@ -39,6 +39,8 @@ func loop(w *app.Window) error {
|
||||||
q := w.Queue()
|
q := w.Queue()
|
||||||
face := faces.For(regular, ui.Sp(16))
|
face := faces.For(regular, ui.Sp(16))
|
||||||
lst := layout.List{Axis: layout.Vertical}
|
lst := layout.List{Axis: layout.Vertical}
|
||||||
|
times := make([]int64, 100)
|
||||||
|
timesIndex := 0
|
||||||
for {
|
for {
|
||||||
e := <-w.Events()
|
e := <-w.Events()
|
||||||
switch e := e.(type) {
|
switch e := e.(type) {
|
||||||
|
@ -54,7 +56,19 @@ func loop(w *app.Window) error {
|
||||||
}
|
}
|
||||||
lst.Layout()
|
lst.Layout()
|
||||||
w.Update(ops)
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
16
slow/main.go
16
slow/main.go
|
@ -37,6 +37,8 @@ func loop(w *app.Window) error {
|
||||||
family := &shape.Family{Regular: regular}
|
family := &shape.Family{Regular: regular}
|
||||||
gtx := &layout.Context{Queue: w.Queue()}
|
gtx := &layout.Context{Queue: w.Queue()}
|
||||||
lst := &layout.List{Axis: layout.Vertical}
|
lst := &layout.List{Axis: layout.Vertical}
|
||||||
|
times := make([]int64, 100)
|
||||||
|
timesIndex := 0
|
||||||
for {
|
for {
|
||||||
e := <-w.Events()
|
e := <-w.Events()
|
||||||
switch e := e.(type) {
|
switch e := e.(type) {
|
||||||
|
@ -51,7 +53,19 @@ func loop(w *app.Window) error {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
w.Update(gtx.Ops)
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user