-
Notifications
You must be signed in to change notification settings - Fork 1
/
benchmark_test.go
96 lines (86 loc) · 1.6 KB
/
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
84
85
86
87
88
89
90
91
92
93
94
95
96
package jdeque
import (
"testing"
gammazero "github.com/gammazero/deque"
)
func doWork(q *Queue[int]) {
for i := 0; i < 10_000_000; i++ {
q.PushFront(i)
}
for i := 0; i < 5_000_000; i++ {
q.PopFront()
}
for i := 0; i < 10_000_000; i++ {
q.PushBack(i)
}
for i := 0; i < 5_000_000; i++ {
q.PopBack()
}
for i := 0; i < 10_000_000; i++ {
q.PopFront()
}
}
// func doWorkDeque(q *deque.Deque[int]) {
// for i := 0; i < 10_000_000; i++ {
// q.PushHead(i)
// }
// for i := 0; i < 5_000_000; i++ {
// q.PopHead()
// }
// for i := 0; i < 10_000_000; i++ {
// q.PushTail(i)
// }
// for i := 0; i < 5_000_000; i++ {
// q.PopTail()
// }
// for i := 0; i < 10_000_000; i++ {
// q.PopHead()
// }
// }
func doWorkGammazero(q *gammazero.Deque[int]) {
for i := 0; i < 10_000_000; i++ {
q.PushFront(i)
}
for i := 0; i < 5_000_000; i++ {
q.PushFront(i)
}
for i := 0; i < 10_000_000; i++ {
q.PushBack(i)
}
for i := 0; i < 5_000_000; i++ {
q.PopBack()
}
for i := 0; i < 10_000_000; i++ {
q.PopBack()
}
}
func BenchmarkJqueue256(b *testing.B) {
q := New[int](256)
for n := 0; n < b.N; n++ {
doWork(q)
}
}
func BenchmarkJqueue1024(b *testing.B) {
q := New[int](1024)
for n := 0; n < b.N; n++ {
doWork(q)
}
}
func BenchmarkJqueue1048576(b *testing.B) {
q := New[int](1024 * 1024)
for n := 0; n < b.N; n++ {
doWork(q)
}
}
// func BenchmarkCarlmjohnson(b *testing.B) {
// q := deque.Make[int](0)
// for n := 0; n < b.N; n++ {
// doWorkDeque(q)
// }
// }
func BenchmarkSekoyo(b *testing.B) {
q := gammazero.New[int](0)
for n := 0; n < b.N; n++ {
doWorkGammazero(q)
}
}