Skip to content

Commit 0caaec1

Browse files
committed
improve hashing performance
1 parent f7fd370 commit 0caaec1

File tree

6 files changed

+207
-347
lines changed

6 files changed

+207
-347
lines changed

README.md

+12-12
Original file line numberDiff line numberDiff line change
@@ -68,28 +68,28 @@ All results were computed from [benchstat](https://pkg.go.dev/golang.org/x/perf/
6868
1. Concurrent Reads Only
6969
```
7070
name time/op
71-
HaxMapReadsOnly-8 8.75µs ± 9%
72-
GoSyncMapReadsOnly-8 22.0µs ±11%
73-
CornelkMapReadsOnly-8 9.20µs ±10%
71+
HaxMapReadsOnly-8 7.13µs ± 5%
72+
GoSyncMapReadsOnly-8 22.4µs ± 2%
73+
CornelkMapReadsOnly-8 8.28µs ± 1%
7474
```
7575

7676

7777
2. Concurrent Reads with Writes
7878
```
7979
name time/op
80-
HaxMapReadsWithWrites-8 10.0µs ± 9%
81-
GoSyncMapReadsWithWrites-8 24.8µs ±11%
82-
CornelkMapReadsWithWrites-8 10.5µs ± 9%
80+
HaxMapReadsWithWrites-8 8.44µs ± 5%
81+
GoSyncMapReadsWithWrites-8 26.1µs ± 2%
82+
CornelkMapReadsWithWrites-8 9.55µs ± 2%
8383
8484
name alloc/op
85-
HaxMapReadsWithWrites-8 1.29kB ± 6%
86-
GoSyncMapReadsWithWrites-8 6.20kB ± 5%
87-
CornelkMapReadsWithWrites-8 1.59kB ±10%
85+
HaxMapReadsWithWrites-8 1.22kB ± 6%
86+
GoSyncMapReadsWithWrites-8 6.06kB ± 6%
87+
CornelkMapReadsWithWrites-8 1.56kB ± 5%
8888
8989
name allocs/op
90-
HaxMapReadsWithWrites-8 161 ± 4%
91-
GoSyncMapReadsWithWrites-8 574 ± 5%
92-
CornelkMapReadsWithWrites-8 198 ±10%
90+
HaxMapReadsWithWrites-8 152 ± 6%
91+
GoSyncMapReadsWithWrites-8 562 ± 6%
92+
CornelkMapReadsWithWrites-8 195 ± 5%
9393
```
9494

9595
From the above results it is evident that `haxmap` takes the least time, memory and allocations in all cases making it the best golang concurrent hashmap in this period of time

benchmarks/go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ replace github.com/alphadose/haxmap => ../
66

77
require (
88
github.com/alphadose/haxmap v0.0.0-00010101000000-000000000000
9-
github.com/cornelk/hashmap v1.0.6
9+
github.com/cornelk/hashmap v1.0.7
1010
)
1111

1212
require github.com/cespare/xxhash v1.1.0 // indirect

benchmarks/go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ github.com/cornelk/hashmap v1.0.5 h1:FetMxz5XPtcXrP1hIbAhsCGyj6L4aa8E+wLS5UrqKm8
66
github.com/cornelk/hashmap v1.0.5/go.mod h1:DqXRj31DMSQGWQJit5c3jpIErEoTlZYmKhAlBGrf0Sw=
77
github.com/cornelk/hashmap v1.0.6 h1:ZNxfMue8uqQdjI36f7e8o8JqqQMcz5ybk7AH5EqfoQM=
88
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=
911
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
1012
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
1113
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72 h1:qLC7fQah7D6K1B0ujays3HV9gkFtllcxhzImRR7ArPQ=

benchmarks/map_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func setupGoSyncMap() *sync.Map {
3030
return m
3131
}
3232

33-
func setupCornelkMap(b *testing.B) *hashmap.HashMap[uintptr, uintptr] {
33+
func setupCornelkMap(b *testing.B) *hashmap.Map[uintptr, uintptr] {
3434
m := hashmap.NewSized[uintptr, uintptr](mapSize)
3535
for i := uintptr(0); i < epochs; i++ {
3636
m.Set(i, i)

0 commit comments

Comments
 (0)