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

mlange-42 / arche-model / 4718758755

17 Apr 2023 07:52AM CUT coverage: 96.144% (+0.2%) from 95.946%
4718758755

push

github

GitHub
RowToTable observer adapter (#37)

20 of 20 new or added lines in 2 files covered. (100.0%)

374 of 389 relevant lines covered (96.14%)

135.41 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
        startSim       time.Time
16
        step           int64
17
}
18

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

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

45
// Finalize the system
46
func (s *PerfTimer) Finalize(w *ecs.World) {
1✔
47
        t := time.Now()
1✔
48
        dur := t.Sub(s.startSim)
1✔
49
        usec := float64(dur.Microseconds()) / float64(s.step)
1✔
50
        fmt.Printf("Total: %d updates, %0.2f us/update\n", s.step, usec)
1✔
51
}
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