2023-06-20 07:55:12 +02:00
|
|
|
package logstorage
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2024-05-12 16:33:29 +02:00
|
|
|
func BenchmarkTryParseTimestampRFC3339Nano(b *testing.B) {
|
|
|
|
a := []string{
|
|
|
|
"2023-01-15T23:45:51Z",
|
|
|
|
"2023-02-15T23:45:51.123Z",
|
|
|
|
"2024-02-15T23:45:51.123456Z",
|
|
|
|
"2025-02-15T22:45:51.123456789Z",
|
|
|
|
"2023-02-15T22:45:51.000000000Z",
|
|
|
|
}
|
|
|
|
|
|
|
|
b.SetBytes(int64(len(a)))
|
|
|
|
b.ReportAllocs()
|
|
|
|
b.RunParallel(func(pb *testing.PB) {
|
|
|
|
for pb.Next() {
|
|
|
|
for _, s := range a {
|
|
|
|
_, ok := tryParseTimestampRFC3339Nano(s)
|
|
|
|
if !ok {
|
|
|
|
panic(fmt.Errorf("cannot parse timestamp %q", s))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-06-20 07:55:12 +02:00
|
|
|
func BenchmarkTryParseTimestampISO8601(b *testing.B) {
|
|
|
|
a := []string{
|
|
|
|
"2023-01-15T23:45:51.123Z",
|
|
|
|
"2023-02-15T23:45:51.123Z",
|
2024-05-12 16:33:29 +02:00
|
|
|
"2024-02-15T23:45:51.123Z",
|
|
|
|
"2025-02-15T22:45:51.123Z",
|
2023-06-20 07:55:12 +02:00
|
|
|
"2023-02-15T22:45:51.000Z",
|
|
|
|
}
|
|
|
|
|
|
|
|
b.SetBytes(int64(len(a)))
|
|
|
|
b.ReportAllocs()
|
|
|
|
b.RunParallel(func(pb *testing.PB) {
|
|
|
|
for pb.Next() {
|
|
|
|
for _, s := range a {
|
|
|
|
_, ok := tryParseTimestampISO8601(s)
|
|
|
|
if !ok {
|
|
|
|
panic(fmt.Errorf("cannot parse timestamp %q", s))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkTryParseIPv4(b *testing.B) {
|
|
|
|
a := []string{
|
|
|
|
"1.2.3.4",
|
|
|
|
"127.0.0.1",
|
|
|
|
"255.255.255.255",
|
|
|
|
"192.43.234.22",
|
|
|
|
"32.34.54.198",
|
|
|
|
}
|
|
|
|
|
|
|
|
b.SetBytes(int64(len(a)))
|
|
|
|
b.ReportAllocs()
|
|
|
|
b.RunParallel(func(pb *testing.PB) {
|
|
|
|
for pb.Next() {
|
|
|
|
for _, s := range a {
|
|
|
|
_, ok := tryParseIPv4(s)
|
|
|
|
if !ok {
|
|
|
|
panic(fmt.Errorf("cannot parse ipv4 %q", s))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkTryParseUint64(b *testing.B) {
|
|
|
|
a := []string{
|
|
|
|
"1234",
|
|
|
|
"483932",
|
|
|
|
"28494",
|
|
|
|
"90012",
|
|
|
|
"889111",
|
|
|
|
}
|
|
|
|
|
|
|
|
b.SetBytes(int64(len(a)))
|
|
|
|
b.ReportAllocs()
|
|
|
|
b.RunParallel(func(pb *testing.PB) {
|
|
|
|
for pb.Next() {
|
|
|
|
for _, s := range a {
|
|
|
|
_, ok := tryParseUint64(s)
|
|
|
|
if !ok {
|
|
|
|
panic(fmt.Errorf("cannot parse uint %q", s))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkTryParseFloat64(b *testing.B) {
|
|
|
|
a := []string{
|
|
|
|
"1.234",
|
|
|
|
"4.545",
|
|
|
|
"456.5645",
|
|
|
|
"-123.434",
|
|
|
|
"434.322",
|
|
|
|
}
|
|
|
|
|
|
|
|
b.SetBytes(int64(len(a)))
|
|
|
|
b.ReportAllocs()
|
|
|
|
b.RunParallel(func(pb *testing.PB) {
|
|
|
|
for pb.Next() {
|
|
|
|
for _, s := range a {
|
|
|
|
_, ok := tryParseFloat64(s)
|
|
|
|
if !ok {
|
|
|
|
panic(fmt.Errorf("cannot parse float64 %q", s))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|