• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mlange-42 / ark-tools / 13609285641 / 1

Source File

100.0
/system/perf_timer.go
1
package system
2

3
import (
4
        "fmt"
5
        "time"
6

7
        "github.com/mlange-42/ark/ecs"
8
)
9

10
// PerfTimer system for printing elapsed time per step, and optional world statistics.
11
type PerfTimer struct {
12
        UpdateInterval int // Update/print interval in ticks.
13
        start          time.Time
14
        startSim       time.Time
15
        step           int64
16
}
17

18
// Initialize the system
19
func (s *PerfTimer) Initialize(w *ecs.World) {
1✔
20
        s.step = 0
1✔
21
}
1✔
22

23
// Update the system
24
func (s *PerfTimer) Update(w *ecs.World) {
30✔
25
        t := time.Now()
30✔
26
        if s.step == 0 {
31✔
27
                s.start = t
1✔
28
                s.startSim = t
1✔
29
        }
1✔
30
        if s.step%int64(s.UpdateInterval) == 0 {
33✔
31
                if s.step > 0 {
5✔
32
                        dur := t.Sub(s.start)
2✔
33
                        usec := float64(dur.Microseconds()) / float64(s.UpdateInterval)
2✔
34
                        fmt.Printf("%d updates, %0.2f us/update\n", s.UpdateInterval, usec)
2✔
35
                }
2✔
36
                s.start = t
3✔
37
        }
38
        s.step++
30✔
39
}
40

41
// Finalize the system
42
func (s *PerfTimer) Finalize(w *ecs.World) {
1✔
43
        t := time.Now()
1✔
44
        dur := t.Sub(s.startSim)
1✔
45
        usec := float64(dur.Microseconds()) / float64(s.step)
1✔
46
        fmt.Printf("Total: %d updates, %0.2f us/update\n", s.step, usec)
1✔
47
}
1✔
  • Back to Build 13609285641
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc