Skip to content

Commit b16cff1

Browse files
committed
Merge branch 'main' of github.com:alphadose/haxmap
2 parents 5a39538 + a1f6979 commit b16cff1

File tree

3 files changed

+56
-23
lines changed

3 files changed

+56
-23
lines changed

Diff for: benchmarks/go.mod

+2-4
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ replace github.com/alphadose/haxmap => ../
77
require (
88
github.com/alphadose/haxmap v0.0.0-00010101000000-000000000000
99
github.com/cornelk/hashmap v1.0.8
10+
github.com/puzpuzpuz/xsync/v2 v2.3.1
1011
)
1112

12-
require (
13-
github.com/cespare/xxhash v1.1.0 // indirect
14-
golang.org/x/exp v0.0.0-20221031165847-c99f073a8326 // indirect
15-
)
13+
require golang.org/x/exp v0.0.0-20221031165847-c99f073a8326 // indirect

Diff for: benchmarks/go.sum

+2-16
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,6 @@
1-
github.com/OneOfOne/xxhash v1.2.2 h1:KMrpdQIwFcEqXDklaen+P1axHaj9BSKzvpUUfnHldSE=
2-
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
3-
github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko=
4-
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
5-
github.com/cornelk/hashmap v1.0.5 h1:FetMxz5XPtcXrP1hIbAhsCGyj6L4aa8E+wLS5UrqKm8=
6-
github.com/cornelk/hashmap v1.0.5/go.mod h1:DqXRj31DMSQGWQJit5c3jpIErEoTlZYmKhAlBGrf0Sw=
7-
github.com/cornelk/hashmap v1.0.6 h1:ZNxfMue8uqQdjI36f7e8o8JqqQMcz5ybk7AH5EqfoQM=
8-
github.com/cornelk/hashmap v1.0.6/go.mod h1:DqXRj31DMSQGWQJit5c3jpIErEoTlZYmKhAlBGrf0Sw=
9-
github.com/cornelk/hashmap v1.0.7 h1:9W5NPASHKJ13gl37bgHNPT4rntj1YFGl5a1Uro7HpA8=
10-
github.com/cornelk/hashmap v1.0.7/go.mod h1:RfZb7JO3RviW/rT6emczVuC/oxpdz4UsSB2LJSclR1k=
111
github.com/cornelk/hashmap v1.0.8 h1:nv0AWgw02n+iDcawr5It4CjQIAcdMMKRrs10HOJYlrc=
122
github.com/cornelk/hashmap v1.0.8/go.mod h1:RfZb7JO3RviW/rT6emczVuC/oxpdz4UsSB2LJSclR1k=
13-
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
14-
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
15-
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72 h1:qLC7fQah7D6K1B0ujays3HV9gkFtllcxhzImRR7ArPQ=
16-
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
17-
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
3+
github.com/puzpuzpuz/xsync/v2 v2.3.1 h1:oAm/nI4ZC+FqOM7t2fnA7DaQVsuj4fO2KcTcNTS1Q9Y=
4+
github.com/puzpuzpuz/xsync/v2 v2.3.1/go.mod h1:gD2H2krq/w52MfPLE+Uy64TzJDVY7lP2znR9qmR35kU=
185
golang.org/x/exp v0.0.0-20221031165847-c99f073a8326 h1:QfTh0HpN6hlw6D3vu8DAwC8pBIwikq0AI1evdm+FksE=
196
golang.org/x/exp v0.0.0-20221031165847-c99f073a8326/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc=
20-
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=

Diff for: benchmarks/map_test.go

+52-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77

88
"github.com/alphadose/haxmap"
99
"github.com/cornelk/hashmap"
10+
"github.com/puzpuzpuz/xsync/v2"
1011
)
1112

1213
const (
@@ -30,14 +31,22 @@ func setupGoSyncMap() *sync.Map {
3031
return m
3132
}
3233

33-
func setupCornelkMap(b *testing.B) *hashmap.Map[uintptr, uintptr] {
34+
func setupCornelkMap() *hashmap.Map[uintptr, uintptr] {
3435
m := hashmap.NewSized[uintptr, uintptr](mapSize)
3536
for i := uintptr(0); i < epochs; i++ {
3637
m.Set(i, i)
3738
}
3839
return m
3940
}
4041

42+
func setupXsyncMap() *xsync.MapOf[uintptr, uintptr] {
43+
m := xsync.NewIntegerMapOf[uintptr, uintptr]()
44+
for i := uintptr(0); i < epochs; i++ {
45+
m.Store(i, i)
46+
}
47+
return m
48+
}
49+
4150
func BenchmarkHaxMapReadsOnly(b *testing.B) {
4251
m := setupHaxMap()
4352
b.ResetTimer()
@@ -119,7 +128,7 @@ func BenchmarkGoSyncMapReadsWithWrites(b *testing.B) {
119128
}
120129

121130
func BenchmarkCornelkMapReadsOnly(b *testing.B) {
122-
m := setupCornelkMap(b)
131+
m := setupCornelkMap()
123132
b.ResetTimer()
124133
b.RunParallel(func(pb *testing.PB) {
125134
for pb.Next() {
@@ -134,7 +143,7 @@ func BenchmarkCornelkMapReadsOnly(b *testing.B) {
134143
}
135144

136145
func BenchmarkCornelkMapReadsWithWrites(b *testing.B) {
137-
m := setupCornelkMap(b)
146+
m := setupCornelkMap()
138147
var writer uintptr
139148
b.ResetTimer()
140149
b.RunParallel(func(pb *testing.PB) {
@@ -157,3 +166,43 @@ func BenchmarkCornelkMapReadsWithWrites(b *testing.B) {
157166
}
158167
})
159168
}
169+
170+
func BenchmarkXsyncMapReadsOnly(b *testing.B) {
171+
m := setupXsyncMap()
172+
b.ResetTimer()
173+
b.RunParallel(func(pb *testing.PB) {
174+
for pb.Next() {
175+
for i := uintptr(0); i < epochs; i++ {
176+
j, _ := m.Load(i)
177+
if j != i {
178+
b.Fail()
179+
}
180+
}
181+
}
182+
})
183+
}
184+
185+
func BenchmarkXsyncMapReadsWithWrites(b *testing.B) {
186+
m := setupXsyncMap()
187+
var writer uintptr
188+
b.ResetTimer()
189+
b.RunParallel(func(pb *testing.PB) {
190+
// use 1 thread as writer
191+
if atomic.CompareAndSwapUintptr(&writer, 0, 1) {
192+
for pb.Next() {
193+
for i := uintptr(0); i < epochs; i++ {
194+
m.Store(i, i)
195+
}
196+
}
197+
} else {
198+
for pb.Next() {
199+
for i := uintptr(0); i < epochs; i++ {
200+
j, _ := m.Load(i)
201+
if j != i {
202+
b.Fail()
203+
}
204+
}
205+
}
206+
}
207+
})
208+
}

0 commit comments

Comments
 (0)