mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-30 07:40:06 +01:00
3383f73191
This is needed for https://github.com/VictoriaMetrics/VictoriaMetrics/pull/5880
55 lines
900 B
Go
55 lines
900 B
Go
package bytesutil
|
|
|
|
import (
|
|
"sync/atomic"
|
|
"testing"
|
|
)
|
|
|
|
func BenchmarkToUnsafeString(b *testing.B) {
|
|
b.ReportAllocs()
|
|
b.SetBytes(int64(len(benchBytes)))
|
|
b.RunParallel(func(pb *testing.PB) {
|
|
n := 0
|
|
for pb.Next() {
|
|
for _, b := range benchBytes {
|
|
s := ToUnsafeString(b)
|
|
n += len(s)
|
|
}
|
|
}
|
|
Sink.Add(uint64(n))
|
|
})
|
|
}
|
|
|
|
func BenchmarkToUnsafeBytes(b *testing.B) {
|
|
b.ReportAllocs()
|
|
b.SetBytes(int64(len(benchStrings)))
|
|
b.RunParallel(func(pb *testing.PB) {
|
|
n := 0
|
|
for pb.Next() {
|
|
for _, s := range benchStrings {
|
|
b := ToUnsafeBytes(s)
|
|
n += len(b)
|
|
}
|
|
}
|
|
Sink.Add(uint64(n))
|
|
})
|
|
}
|
|
|
|
var benchBytes = func() [][]byte {
|
|
a := make([][]byte, 1000)
|
|
for i := range a {
|
|
a[i] = make([]byte, i)
|
|
}
|
|
return a
|
|
}()
|
|
|
|
var benchStrings = func() []string {
|
|
a := make([]string, 1000)
|
|
for i := range a {
|
|
a[i] = string(make([]byte, i))
|
|
}
|
|
return a
|
|
}()
|
|
|
|
var Sink atomic.Uint64
|