Skip to content

Commit 03b4514

Browse files
committed
added benchmark for timer
1 parent 1d8d037 commit 03b4514

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

timer/timer.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,6 @@ type Tick struct {
2424
tasks []*Task
2525
}
2626

27-
func NewTick() *Tick {
28-
return &Tick{
29-
tasks: make([]*Task, 0),
30-
}
31-
}
32-
3327
func (t *Tick) register(task *Task) {
3428
t.tasks = append(t.tasks, task)
3529
}

timer/timer_bench_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package timer
2+
3+
import (
4+
"math/rand"
5+
"testing"
6+
"time"
7+
)
8+
9+
func BenchmarkCreateTask(b *testing.B) {
10+
timer := NewTimer(1000, 59, time.Millisecond)
11+
go timer.Start()
12+
13+
for i := 0; i < b.N; i++ {
14+
timer.Task(uint(rand.Intn(10000)))
15+
}
16+
}

timer/timer_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func TestTaskMethodDoneShouldBeOpening(t *testing.T) {
2121
}
2222

2323
func TestTickMethodRegisterAppendTaskSucceed(t *testing.T) {
24-
tick := NewTick()
24+
tick := &Tick{tasks: make([]*Task, 0)}
2525

2626
tick.register(newTask(1))
2727

0 commit comments

Comments
 (0)