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

mlange-42 / arche-model / 4702695229

14 Apr 2023 06:14PM CUT coverage: 95.946%. Remained the same
4702695229

push

github

GitHub
Feature list and example for README (#35)

355 of 370 relevant lines covered (95.95%)

142.3 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/system/perf_timer.go
1
package system
2

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

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

10
// PerfTimer system for printing elapsed time per model step, and optional world statistics.
11
type PerfTimer struct {
12
        UpdateInterval int  // Update/print interval in model ticks.
13
        Stats          bool // Whether to print world stats.
14
        start          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
        }
1✔
29
        if s.step%int64(s.UpdateInterval) == 0 {
33✔
30
                if s.step > 0 {
5✔
31
                        dur := t.Sub(s.start)
2✔
32
                        usec := float64(dur.Microseconds()) / float64(s.UpdateInterval)
2✔
33
                        fmt.Printf("%d updates, %0.2f us/update\n", s.UpdateInterval, usec)
2✔
34
                }
2✔
35
                if s.Stats {
6✔
36
                        fmt.Println(w.Stats().String())
3✔
37
                }
3✔
38
                s.start = t
3✔
39
        }
40
        s.step++
30✔
41
}
42

43
// Finalize the system
44
func (s *PerfTimer) Finalize(w *ecs.World) {}
1✔
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