mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-04 16:51:11 +01:00
7e1dd8ab9d
See ea9e2b19a5
41 lines
684 B
Go
41 lines
684 B
Go
package bytesutil
|
|
|
|
import (
|
|
"sync/atomic"
|
|
"testing"
|
|
)
|
|
|
|
func BenchmarkToUnsafeString(b *testing.B) {
|
|
buf := []byte("foobarbaz abcde fafdsfds")
|
|
b.ReportAllocs()
|
|
b.SetBytes(int64(len(buf)))
|
|
b.RunParallel(func(pb *testing.PB) {
|
|
n := 0
|
|
for pb.Next() {
|
|
for i := range buf {
|
|
s := ToUnsafeString(buf[:i])
|
|
n += len(s)
|
|
}
|
|
}
|
|
Sink.Add(uint64(n))
|
|
})
|
|
}
|
|
|
|
func BenchmarkToUnsafeBytes(b *testing.B) {
|
|
s := "foobarbaz abcde fafdsfds"
|
|
b.ReportAllocs()
|
|
b.SetBytes(int64(len(s)))
|
|
b.RunParallel(func(pb *testing.PB) {
|
|
n := 0
|
|
for pb.Next() {
|
|
for i := range s {
|
|
s := ToUnsafeBytes(s[:i])
|
|
n += len(s)
|
|
}
|
|
}
|
|
Sink.Add(uint64(n))
|
|
})
|
|
}
|
|
|
|
var Sink atomic.Uint64
|