Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,15 @@ make bench

| Benchmark | Iterations | ns/op | B/op | allocs/op |
|------------------------------------------------------------|------------|------:|------:|----------:|
| [ConvertSyncMapToUint32Slice](tx_map_benchmarks_test.go) | 78,904 | 15365 | 12920 | 11 |
| [ConvertSyncedMapToUint32Slice](tx_map_benchmarks_test.go) | 46,190 | 22160 | 12920 | 11 |
| [Bytes2Uint16Buckets](tx_map_benchmarks_test.go) | 1,000,000,000 | 1 | 0 | 0 |
| [ConvertSyncMapToUint32Slice](tx_map_benchmarks_test.go) | 86,636 | 13312 | 12920 | 11 |
| [ConvertSyncedMapToUint32Slice](tx_map_benchmarks_test.go) | 57,505 | 20754 | 12920 | 11 |
| [NewSplitSwissLockFreeMapUint64](tx_map_benchmarks_test.go)| 4,792 | 414742 | 442192 | 4112 |
| [NewSplitSwissMap](tx_map_benchmarks_test.go) | 2,715 | 423537 | 840626 | 4107 |
| [NewSplitSwissMapUint64](tx_map_benchmarks_test.go) | 2,401 | 465790 | 868603 | 4112 |
| [NewSwissLockFreeMapUint64](tx_map_benchmarks_test.go) | 251,127 | 5740 | 19664 | 3 |
| [NewSwissMap](tx_map_benchmarks_test.go) | 117,189 | 9331 | 42192 | 3 |
| [NewSwissMapUint64](tx_map_benchmarks_test.go) | 125,695 | 11093 | 50384 | 3 |

> These benchmarks reflect fast, allocation-free lookups for most retrieval functions, ensuring optimal performance in production environments.
> Performance benchmarks for the core functions in this library, executed on an Apple M1 Max (ARM64).
Expand Down
87 changes: 87 additions & 0 deletions tx_map_benchmarks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,22 @@ package txmap
import (
"sync"
"testing"

"github.com/libsv/go-bt/v2/chainhash"
)

// BenchmarkBytes2Uint16Buckets measures the performance of Bytes2Uint16Buckets.
func BenchmarkBytes2Uint16Buckets(b *testing.B) {
hash := chainhash.Hash{0x01, 0x02}

b.ReportAllocs()
b.ResetTimer()

for i := 0; i < b.N; i++ {
_ = Bytes2Uint16Buckets(hash, 1024)
}
}

// BenchmarkConvertSyncMapToUint32Slice measures the performance of converting
// a sync.Map to a slice of uint32 values.
func BenchmarkConvertSyncMapToUint32Slice(b *testing.B) {
Expand Down Expand Up @@ -40,3 +54,76 @@ func BenchmarkConvertSyncedMapToUint32Slice(b *testing.B) {
}
}
}

// BenchmarkNewSplitSwissLockFreeMapUint64 measures constructing a
// SplitSwissLockFreeMapUint64.
func BenchmarkNewSplitSwissLockFreeMapUint64(b *testing.B) {
b.ReportAllocs()
b.ResetTimer()

for i := 0; i < b.N; i++ {
if NewSplitSwissLockFreeMapUint64(1000) == nil {
b.Fatal("map should not be nil")
}
}
}

// BenchmarkNewSplitSwissMap measures constructing a SplitSwissMap.
func BenchmarkNewSplitSwissMap(b *testing.B) {
b.ReportAllocs()
b.ResetTimer()

for i := 0; i < b.N; i++ {
if NewSplitSwissMap(1000) == nil {
b.Fatal("map should not be nil")
}
}
}

// BenchmarkNewSplitSwissMapUint64 measures constructing a SplitSwissMapUint64.
func BenchmarkNewSplitSwissMapUint64(b *testing.B) {
b.ReportAllocs()
b.ResetTimer()

for i := 0; i < b.N; i++ {
if NewSplitSwissMapUint64(1000) == nil {
b.Fatal("map should not be nil")
}
}
}

// BenchmarkNewSwissLockFreeMapUint64 measures constructing a SwissLockFreeMapUint64.
func BenchmarkNewSwissLockFreeMapUint64(b *testing.B) {
b.ReportAllocs()
b.ResetTimer()

for i := 0; i < b.N; i++ {
if NewSwissLockFreeMapUint64(1000) == nil {
b.Fatal("map should not be nil")
}
}
}

// BenchmarkNewSwissMap measures constructing a SwissMap.
func BenchmarkNewSwissMap(b *testing.B) {
b.ReportAllocs()
b.ResetTimer()

for i := 0; i < b.N; i++ {
if NewSwissMap(1000) == nil {
b.Fatal("map should not be nil")
}
}
}

// BenchmarkNewSwissMapUint64 measures constructing a SwissMapUint64.
func BenchmarkNewSwissMapUint64(b *testing.B) {
b.ReportAllocs()
b.ResetTimer()

for i := 0; i < b.N; i++ {
if NewSwissMapUint64(1000) == nil {
b.Fatal("map should not be nil")
}
}
}
Loading