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

kelindar / timeline / 17122299990

21 Aug 2025 09:03AM UTC coverage: 60.477% (-38.2%) from 98.701%
17122299990

push

github

web-flow
Move to kelindar/bench (#8)

* Move to kelindar/bench

* v125

4 of 69 new or added lines in 2 files covered. (5.8%)

228 of 377 relevant lines covered (60.48%)

93.2 hits per line

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

0.0
/example/bench/main.go
1
package main
2

3
import (
4
        "sync/atomic"
5
        "time"
6

7
        "github.com/kelindar/bench"
8
        "github.com/kelindar/timeline"
9
        "github.com/kelindar/timeline/emit"
10
)
11

NEW
12
func main() {
×
NEW
13
        bench.Run(benchmark,
×
NEW
14
                bench.WithDuration(5*time.Millisecond),
×
NEW
15
                bench.WithSamples(100),
×
NEW
16
        )
×
NEW
17
}
×
18

NEW
19
func benchmark(b *bench.B) {
×
NEW
20
        s := timeline.New()
×
NEW
21
        var counter atomic.Uint64
×
NEW
22
        const batch = 10
×
NEW
23

×
NEW
24
        emit.On(func(event *ByPointer, now time.Time, elapsed time.Duration) error {
×
NEW
25
                counter.Add(1)
×
NEW
26
                return nil
×
NEW
27
        })
×
28

NEW
29
        emit.On(func(event ByValue, now time.Time, elapsed time.Duration) error {
×
NEW
30
                counter.Add(1)
×
NEW
31
                return nil
×
NEW
32
        })
×
33

NEW
34
        b.RunN("timeline-next", func(i int) int {
×
NEW
35
                for i := 0; i < batch; i++ {
×
NEW
36
                        s.Run(func(now time.Time, elapsed time.Duration) bool {
×
NEW
37
                                counter.Add(1)
×
NEW
38
                                return true
×
NEW
39
                        })
×
40
                }
NEW
41
                s.Tick()
×
NEW
42
                return batch
×
43
        })
44

NEW
45
        b.RunN("timeline-after", func(i int) int {
×
NEW
46
                for i := 0; i < batch; i++ {
×
NEW
47
                        s.RunAfter(func(now time.Time, elapsed time.Duration) bool {
×
NEW
48
                                counter.Add(1)
×
NEW
49
                                return true
×
NEW
50
                        }, time.Duration(10*i)*time.Millisecond)
×
51
                }
NEW
52
                s.Tick()
×
NEW
53
                return batch
×
54
        })
55

NEW
56
        b.RunN("emit-next-ptr", func(i int) int {
×
NEW
57
                for i := 0; i < batch; i++ {
×
NEW
58
                        emit.Next(&ByPointer{Number: i, String: "test"})
×
NEW
59
                }
×
NEW
60
                s.Tick()
×
NEW
61
                return batch
×
62
        })
63

NEW
64
        b.RunN("emit-after-ptr", func(i int) int {
×
NEW
65
                for i := 0; i < batch; i++ {
×
NEW
66
                        emit.After(&ByPointer{Number: i, String: "test"}, time.Duration(10*i)*time.Millisecond)
×
NEW
67
                }
×
NEW
68
                s.Tick()
×
NEW
69
                return batch
×
70
        })
71

NEW
72
        b.RunN("emit-next-val", func(i int) int {
×
NEW
73
                for i := 0; i < batch; i++ {
×
NEW
74
                        emit.Next(ByValue{Number: i, String: "test"})
×
NEW
75
                }
×
NEW
76
                s.Tick()
×
NEW
77
                return batch
×
78
        })
79

NEW
80
        b.RunN("emit-after-val", func(i int) int {
×
NEW
81
                for i := 0; i < batch; i++ {
×
NEW
82
                        emit.After(ByValue{Number: i, String: "test"}, time.Duration(10*i)*time.Millisecond)
×
NEW
83
                }
×
NEW
84
                s.Tick()
×
NEW
85
                return batch
×
86
        })
87

88
}
89

90
type ByPointer struct {
91
        Number int
92
        String string
93
}
94

NEW
95
func (t *ByPointer) Type() uint32 {
×
NEW
96
        return 0x01
×
NEW
97
}
×
98

99
type ByValue struct {
100
        Number int
101
        String string
102
}
103

NEW
104
func (t ByValue) Type() uint32 {
×
NEW
105
        return 0x02
×
NEW
106
}
×
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

© 2026 Coveralls, Inc