-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlangton_benchmark_test.go
83 lines (72 loc) · 1.29 KB
/
langton_benchmark_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package langton
import (
"testing"
)
func BenchmarkGridGetInc(b *testing.B) {
g := NewGrid(Pt(10, 10), 2)
for range b.N {
g.GetInc(Pt(5, 5))
}
}
func BenchmarkOrientationRotateRight1(b *testing.B) {
o := OrientationUp
for range b.N {
o = o.Rotate(1)
}
}
func BenchmarkOrientationRotateRight5(b *testing.B) {
o := OrientationUp
for range b.N {
o = o.Rotate(5)
}
}
func BenchmarkOrientationRotateLeft1(b *testing.B) {
o := OrientationUp
for range b.N {
o = o.Rotate(-1)
}
}
func BenchmarkOrientationRotateLeft5(b *testing.B) {
o := OrientationUp
for range b.N {
o = o.Rotate(-5)
}
}
func BenchmarkAntMoveUp(b *testing.B) {
a := &Ant{Orientation: OrientationUp}
for range b.N {
a.Move(1)
}
}
func BenchmarkAntMoveRight(b *testing.B) {
a := &Ant{Orientation: OrientationRight}
for range b.N {
a.Move(1)
}
}
func BenchmarkAntMoveDown(b *testing.B) {
a := &Ant{Orientation: OrientationDown}
for range b.N {
a.Move(1)
}
}
func BenchmarkAntMoveLeft(b *testing.B) {
a := &Ant{Orientation: OrientationLeft}
for range b.N {
a.Move(1)
}
}
func BenchmarkGameStep(b *testing.B) {
g := &Game{
Rules: RulesBasic,
Grid: NewGrid(Pt(20, 20), 2),
Ants: []*Ant{{
Location: Pt(10, 10),
Orientation: OrientationUp,
}},
}
b.ResetTimer()
for range b.N {
g.Step()
}
}