-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Type-safe conversion for line-protocol Addfield #43
Milestone
Comments
6 tasks
Hi @arukiidou, Thank you for raising the issue and submitting your PR. I have a preference for Variant A. Best regards |
benchmarking✅ This is not only type safe, lower memory allocation and performance improvement.
func BenchmarkAddField(b *testing.B) {
// cpu: Intel(R) Core(TM) i5-10400 CPU @ 2.90GHz
// BenchmarkAddPoint-12 3410827 345.9 ns/op 152 B/op 9 allocs/op
// BenchmarkNewValueFromTyped-12 9870652 122.6 ns/op 48 B/op 2 allocs/op
// BenchmarkNewValueFromNative-12 4241845 282.0 ns/op 112 B/op 7 allocs/op
p := NewPoint(
"bench",
map[string]string{
"id": "10ad=",
"ven=dor": "AWS",
`host"name`: `ho\st "a"`,
`x\" x`: "a b",
},
map[string]interface{}{},
time.Unix(60, 70))
f := float64(80.1234567)
ints := int64(-1234567890)
u := uint64(12345677890)
s := string(`six, "seven", eight`)
bt := []byte(`six=seven\, eight`)
bl := bool(false)
b.ResetTimer()
for i := 0; i < b.N; i++ {
p.AddField("float64", f)
p.AddField("int64", ints)
p.AddField("uint64", u)
p.AddField("string", s)
p.AddField("bytes", bt)
p.AddField("bool", bl)
}
}
func BenchmarkNewValueFromTyped(b *testing.B) {
// BenchmarkNewValueFromTyped-12 9870652 122.6 ns/op 48 B/op 2 allocs/op
// BenchmarkNewValueFromNative-12 4241845 282.0 ns/op 112 B/op 7 allocs/op
p := NewPoint(
"bench",
map[string]string{
"id": "10ad=",
"ven=dor": "AWS",
`host"name`: `ho\st "a"`,
`x\" x`: "a b",
},
map[string]interface{}{},
time.Unix(60, 70))
f := float64(80.1234567)
ints := int64(-1234567890)
u := uint64(12345677890)
s := string(`six, "seven", eight`)
bt := []byte(`six=seven\, eight`)
bl := bool(false)
b.ResetTimer()
for i := 0; i < b.N; i++ {
p.AddFieldFromValue("float64", NewValueFromFloat(f))
p.AddFieldFromValue("int64", NewValueFromInt(ints))
p.AddFieldFromValue("uint64", NewValueFromUInt(u))
p.AddFieldFromValue("string", NewValueFromString(s))
p.AddFieldFromValue("bytes", NewValueFromString(bt))
p.AddFieldFromValue("bool", NewValueFromBoolean(bl))
}
}
func BenchmarkNewValueFromNative(b *testing.B) {
// BenchmarkNewValueFromNative-12 4241845 282.0 ns/op 112 B/op 7 allocs/op
p := NewPoint(
"bench",
map[string]string{
"id": "10ad=",
"ven=dor": "AWS",
`host"name`: `ho\st "a"`,
`x\" x`: "a b",
},
map[string]interface{}{},
time.Unix(60, 70))
f := float64(80.1234567)
ints := int64(-1234567890)
u := uint64(12345677890)
s := string(`six, "seven", eight`)
bt := []byte(`six=seven\, eight`)
bl := bool(false)
b.ResetTimer()
for i := 0; i < b.N; i++ {
p.AddFieldFromValue("float64", NewValueFromNative(f))
p.AddFieldFromValue("int64", NewValueFromNative(ints))
p.AddFieldFromValue("uint64", NewValueFromNative(u))
p.AddFieldFromValue("string", NewValueFromNative(s))
p.AddFieldFromValue("bytes", NewValueFromNative(bt))
p.AddFieldFromValue("bool", NewValueFromNative(bl))
}
} AddFieldNewValueFrom-TypedNewValueFrom-Native |
Closed
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use Case
Expected behavior
Actual behavior
Additional info
NewValueFrom
(Retracted)NewFieldFrom
Why not line-protocol?
The text was updated successfully, but these errors were encountered: