Files
Reticulum-Go/pkg/transport/transport_test.go
Sudo-Ivan 8e243a7c8b
All checks were successful
Go Build Multi-Platform / build (amd64, windows) (push) Successful in 34s
Go Build Multi-Platform / build (amd64, freebsd) (push) Successful in 38s
Go Build Multi-Platform / build (amd64, linux) (push) Successful in 37s
Go Build Multi-Platform / build (arm, freebsd) (push) Successful in 32s
Go Build Multi-Platform / build (arm, linux) (push) Successful in 35s
Go Build Multi-Platform / build (arm64, darwin) (push) Successful in 34s
Go Build Multi-Platform / build (arm, windows) (push) Successful in 37s
Go Build Multi-Platform / build (arm64, freebsd) (push) Successful in 42s
Go Build Multi-Platform / Create Release (push) Has been skipped
Go Test Multi-Platform / Test (ubuntu-latest, amd64) (push) Successful in 1m29s
Go Revive Lint / lint (push) Successful in 47s
Run Gosec / tests (push) Successful in 1m3s
Go Build Multi-Platform / build (amd64, darwin) (push) Successful in 27s
Go Build Multi-Platform / build (arm64, linux) (push) Successful in 44s
Go Build Multi-Platform / build (arm64, windows) (push) Successful in 42s
Go Test Multi-Platform / Test (ubuntu-latest, arm64) (push) Successful in 1m5s
Update import paths to use the new Gitea paths
2025-12-20 20:02:49 -06:00

89 lines
2.2 KiB
Go

package transport
import (
"crypto/rand"
"testing"
"git.quad4.io/Networks/Reticulum-Go/pkg/common"
)
func randomBytes(n int) []byte {
b := make([]byte, n)
_, err := rand.Read(b)
if err != nil {
panic("Failed to generate random bytes: " + err.Error())
}
return b
}
// BenchmarkTransportDestinationCreation benchmarks destination creation
func BenchmarkTransportDestinationCreation(b *testing.B) {
// Create a basic config for transport
config := &common.ReticulumConfig{
ConfigPath: "/tmp/test_config",
}
transport := NewTransport(config)
b.ResetTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
// Create destination (this allocates and initializes destination objects)
dest := transport.NewDestination(nil, OUT, SINGLE, "test_app")
_ = dest // Use the destination to avoid optimization
}
}
// BenchmarkTransportPathLookup benchmarks path lookup operations
func BenchmarkTransportPathLookup(b *testing.B) {
// Create a basic config for transport
config := &common.ReticulumConfig{
ConfigPath: "/tmp/test_config",
}
transport := NewTransport(config)
// Pre-populate with some destinations
destHash1 := randomBytes(16)
destHash2 := randomBytes(16)
destHash3 := randomBytes(16)
// Create some destinations
transport.NewDestination(nil, OUT, SINGLE, "test_app")
transport.NewDestination(nil, OUT, SINGLE, "test_app")
transport.NewDestination(nil, OUT, SINGLE, "test_app")
b.ResetTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
// Test path lookup operations (these involve map lookups and allocations)
_ = transport.HasPath(destHash1)
_ = transport.HasPath(destHash2)
_ = transport.HasPath(destHash3)
}
}
// BenchmarkTransportHopsCalculation benchmarks hops calculation
func BenchmarkTransportHopsCalculation(b *testing.B) {
// Create a basic config for transport
config := &common.ReticulumConfig{
ConfigPath: "/tmp/test_config",
}
transport := NewTransport(config)
// Create some destinations
destHash := randomBytes(16)
transport.NewDestination(nil, OUT, SINGLE, "test_app")
b.ResetTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
// Test hops calculation (involves internal data structure access)
_ = transport.HopsTo(destHash)
}
}