reworking how I actually want to publish the telemetry data for now

This commit is contained in:
2026-03-06 14:30:52 +00:00
parent 9b10042112
commit 6e98f13eb5
4 changed files with 180 additions and 39 deletions
+51
View File
@@ -0,0 +1,51 @@
package telemetry
import (
"encoding/binary"
"testing"
)
var (
testRaw uint64 = 0x1122334455667788
sink []byte
)
// The "Manual" way (with the fix for the missing 24-bit shift)
func BenchmarkPackManual(b *testing.B) {
for i := 0; i < b.N; i++ {
buf := make([]byte, 0, 8)
buf = append(buf,
uint8(testRaw),
uint8(testRaw>>8),
uint8(testRaw>>16),
uint8(testRaw>>24),
uint8(testRaw>>32),
uint8(testRaw>>40),
uint8(testRaw>>48),
uint8(testRaw>>56),
)
sink = buf
}
}
// The "Loop" way
func BenchmarkPackLoop(b *testing.B) {
for i := 0; i < b.N; i++ {
buf := make([]byte, 0, 8)
for j := 0; j < 8; j++ {
buf = append(buf, uint8(testRaw>>(j*8)))
}
sink = buf
}
}
// The "Binary + Stack Array" way (Best Practice)
func BenchmarkPackBinary(b *testing.B) {
for i := 0; i < b.N; i++ {
buf := make([]byte, 0, 8)
var temp [8]byte
binary.LittleEndian.PutUint64(temp[:], testRaw)
buf = append(buf, temp[:]...)
sink = buf
}
}