mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
lib/bytesutil: add benchmarks for ToUnsafeString() and ToUnsafeBytes()
This commit is contained in:
parent
6108ef1758
commit
b7239c2221
1 changed files with 40 additions and 0 deletions
40
lib/bytesutil/bytesutil_timing_test.go
Normal file
40
lib/bytesutil/bytesutil_timing_test.go
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
atomic.AddUint64(&Sink, 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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
atomic.AddUint64(&Sink, uint64(n))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
var Sink uint64
|
Loading…
Reference in a new issue