Skip to content

Commit eadfe36

Browse files
committed
Release
1 parent 429f212 commit eadfe36

File tree

4 files changed

+73
-56
lines changed

4 files changed

+73
-56
lines changed

armap_benchmark_test.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package armap
2+
3+
import (
4+
"testing"
5+
)
6+
7+
func BenchmarkMap(b *testing.B) {
8+
b.Run("map", func(tb *testing.B) {
9+
m := make(map[int]int, tb.N)
10+
for i := 0; i < tb.N; i += 1 {
11+
m[i] = i
12+
}
13+
for i := 0; i < tb.N; i += 1 {
14+
_, _ = m[i]
15+
}
16+
for i := 0; i < tb.N; i += 1 {
17+
delete(m, i)
18+
}
19+
})
20+
b.Run("armap", func(tb *testing.B) {
21+
a := NewArena(1*1024*1024, 400)
22+
m := NewMap[int, int](a, WithCapacity(tb.N))
23+
defer m.Release()
24+
for i := 0; i < tb.N; i += 1 {
25+
m.Set(i, i)
26+
}
27+
for i := 0; i < tb.N; i += 1 {
28+
_, _ = m.Get(i)
29+
}
30+
for i := 0; i < tb.N; i += 1 {
31+
_, _ = m.Delete(i)
32+
}
33+
})
34+
}
35+
36+
func BenchmarkSet(b *testing.B) {
37+
b.Run("map", func(tb *testing.B) {
38+
m := make(map[int]struct{}, tb.N)
39+
for i := 0; i < tb.N; i += 1 {
40+
m[i] = struct{}{}
41+
}
42+
for i := 0; i < tb.N; i += 1 {
43+
_, _ = m[i]
44+
}
45+
for i := 0; i < tb.N; i += 1 {
46+
delete(m, i)
47+
}
48+
})
49+
b.Run("armap", func(tb *testing.B) {
50+
a := NewArena(1*1024*1024, 400)
51+
m := NewSet[int](a, WithCapacity(tb.N))
52+
defer m.Release()
53+
for i := 0; i < tb.N; i += 1 {
54+
m.Add(i)
55+
}
56+
for i := 0; i < tb.N; i += 1 {
57+
_ = m.Contains(i)
58+
}
59+
for i := 0; i < tb.N; i += 1 {
60+
_ = m.Delete(i)
61+
}
62+
})
63+
}

linkedlist_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ func TestLinkedList(t *testing.T) {
99
t.Run("string,string", func(tt *testing.T) {
1010
a := NewArena(1000, 10)
1111
l := NewLinkedList[string, string](a)
12+
defer l.Release()
13+
1214
l.Push("hello", "world")
1315
l.Push("foo", "bar")
1416
l.Push("test", "testvalue")
@@ -52,6 +54,8 @@ func TestLinkedList(t *testing.T) {
5254
t.Run("push/delete/scan", func(tt *testing.T) {
5355
a := NewArena(1000, 10)
5456
l := NewLinkedList[string, string](a)
57+
defer l.Release()
58+
5559
l.Push("test1", "t1")
5660
l.Push("test2", "t2")
5761
l.Push("test3", "t3")

map_test.go

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,39 +5,12 @@ import (
55
"testing"
66
)
77

8-
func BenchmarkMap(b *testing.B) {
9-
b.Run("map", func(tb *testing.B) {
10-
m := make(map[int]int, tb.N)
11-
for i := 0; i < tb.N; i += 1 {
12-
m[i] = i
13-
}
14-
for i := 0; i < tb.N; i += 1 {
15-
_, _ = m[i]
16-
}
17-
for i := 0; i < tb.N; i += 1 {
18-
delete(m, i)
19-
}
20-
})
21-
b.Run("armap", func(tb *testing.B) {
22-
a := NewArena(1024*1024, 4)
23-
m := NewMap[int, int](a, WithCapacity(tb.N))
24-
for i := 0; i < tb.N; i += 1 {
25-
m.Set(i, i)
26-
}
27-
for i := 0; i < tb.N; i += 1 {
28-
_, _ = m.Get(i)
29-
}
30-
for i := 0; i < tb.N; i += 1 {
31-
_, _ = m.Delete(i)
32-
}
33-
})
34-
}
35-
368
func TestMap(t *testing.T) {
379
t.Run("1000", func(tt *testing.T) {
3810
N := 10
3911
a := NewArena(1024*1024, 4)
4012
m := NewMap[string, string](a, WithCapacity(N))
13+
defer m.Release()
4114

4215
keys := make([]string, N)
4316
for i := 0; i < N; i += 1 {
@@ -93,6 +66,8 @@ func TestMap(t *testing.T) {
9366

9467
a := NewArena(1000, 10)
9568
m := NewMap[string, string](a)
69+
defer m.Release()
70+
9671
old1, found1 := m.Set(key1, value1)
9772
if found1 {
9873
tt.Errorf("key1 is not exists: %s", old1)

set_test.go

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,39 +5,12 @@ import (
55
"testing"
66
)
77

8-
func BenchmarkSet(b *testing.B) {
9-
b.Run("map", func(tb *testing.B) {
10-
m := make(map[int]struct{}, tb.N)
11-
for i := 0; i < tb.N; i += 1 {
12-
m[i] = struct{}{}
13-
}
14-
for i := 0; i < tb.N; i += 1 {
15-
_, _ = m[i]
16-
}
17-
for i := 0; i < tb.N; i += 1 {
18-
delete(m, i)
19-
}
20-
})
21-
b.Run("armap", func(tb *testing.B) {
22-
a := NewArena(1024*1024, 4)
23-
m := NewSet[int](a, WithCapacity(tb.N))
24-
for i := 0; i < tb.N; i += 1 {
25-
m.Add(i)
26-
}
27-
for i := 0; i < tb.N; i += 1 {
28-
_ = m.Contains(i)
29-
}
30-
for i := 0; i < tb.N; i += 1 {
31-
_ = m.Delete(i)
32-
}
33-
})
34-
}
35-
368
func TestSet(t *testing.T) {
379
t.Run("10000", func(tt *testing.T) {
3810
N := 10_000
3911
a := NewArena(1024*1024, 4)
4012
m := NewSet[string](a, WithCapacity(N))
13+
defer m.Release()
4114

4215
keys := make([]string, N)
4316
for i := 0; i < N; i += 1 {
@@ -68,6 +41,8 @@ func TestSet(t *testing.T) {
6841
t.Run("string", func(tt *testing.T) {
6942
a := NewArena(1000, 10)
7043
s := NewSet[string](a)
44+
defer s.Release()
45+
7146
if ok := s.Add("test1"); ok {
7247
tt.Errorf("test1 is new key")
7348
}

0 commit comments

Comments
 (0)