mirror of
https://github.com/sonr-io/sonr.git
synced 2026-08-02 17:31:39 +00:00
61 lines
1.3 KiB
Go
61 lines
1.3 KiB
Go
package handlers
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
|
|
"github.com/sonr-io/sonr/crypto/mpc"
|
|
)
|
|
|
|
// getQueueFromPriority returns the queue name based on priority
|
|
func getQueueFromPriority(priority string) string {
|
|
return GetQueueFromPriority(priority)
|
|
}
|
|
|
|
// BenchmarkJSONMarshaling measures JSON encoding/decoding performance
|
|
func BenchmarkJSONMarshaling(b *testing.B) {
|
|
payload := map[string]any{
|
|
"message": []byte("benchmark test message for JSON marshaling performance"),
|
|
"enclave": &mpc.EnclaveData{},
|
|
"priority": "critical",
|
|
}
|
|
|
|
b.ResetTimer()
|
|
b.ReportAllocs()
|
|
|
|
b.RunParallel(func(pb *testing.PB) {
|
|
for pb.Next() {
|
|
// Marshal
|
|
data, err := json.Marshal(payload)
|
|
if err != nil {
|
|
b.Error(err)
|
|
}
|
|
|
|
// Unmarshal
|
|
var decoded map[string]any
|
|
err = json.Unmarshal(data, &decoded)
|
|
if err != nil {
|
|
b.Error(err)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
|
|
// BenchmarkQueuePrioritySelection measures queue selection performance
|
|
func BenchmarkQueuePrioritySelection(b *testing.B) {
|
|
priorities := []string{"critical", "high", "default", "low", "", "unknown"}
|
|
|
|
b.ResetTimer()
|
|
b.ReportAllocs()
|
|
|
|
b.RunParallel(func(pb *testing.PB) {
|
|
i := 0
|
|
for pb.Next() {
|
|
priority := priorities[i%len(priorities)]
|
|
i++
|
|
queue := getQueueFromPriority(priority)
|
|
_ = queue // Avoid compiler optimization
|
|
}
|
|
})
|
|
}
|