We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Hi,
currently, XmlNode.SetContent() can both receive string/[]byte param for code conveniece,
func (xmlNode *XmlNode) SetContent(content interface{}) (err error) { switch data := content.(type) { default: err = ERR_UNDEFINED_SET_CONTENT_PARAM case string: err = xmlNode.SetContent([]byte(data)) case []byte: contentBytes := GetCString(data) contentPtr := unsafe.Pointer(&contentBytes[0]) C.xmlSetContent(unsafe.Pointer(xmlNode), unsafe.Pointer(xmlNode.Ptr), contentPtr) } return }
But content.(type) and once more function call may cost more resource, below is my bechmark codes:
package fakeOverload import "testing" func SetContent(content interface{}) { switch data := content.(type) { case string: SetContent([]byte(data)) case []byte: _ = content } } func SetContentBytes(bytes []byte) { _ = bytes } func BenchmarkSetContent(t *testing.B) { str := "test" for i := 0; i < t.N; i++ { SetContent(str) } } func BenchmarkSetContentBytes(t *testing.B) { str := "test" for i := 0; i < t.N; i++ { SetContentBytes([]byte(str)) } }
below is result:
PASS BenchmarkSetContent testing: warning: no tests to run 50000000 260 ns/op 58 B/op 2 allocs/op BenchmarkSetContentBytes 200000000 37.9 ns/op 8 B/op 0 allocs/op ok _/home/xxxx/benchmark/testFakeOverloadFunc 24.776s
we can see that if use SetContent() cost 6 times time and 7 times memory than SetContentBytes(),
how about use two functions:
SetContent(content string) SetContentBytes(content []byte)
Thank you! :)
The text was updated successfully, but these errors were encountered:
+1 for this. Gokogiri is a pretty low level api that may be called many times over in a loop and this should help with resource usage.
Sorry, something went wrong.
No branches or pull requests
Hi,
currently, XmlNode.SetContent() can both receive string/[]byte param for code conveniece,
But content.(type) and once more function call may cost more resource, below is my bechmark codes:
below is result:
we can see that if use SetContent() cost 6 times time and 7 times memory than SetContentBytes(),
how about use two functions:
Thank you! :)
The text was updated successfully, but these errors were encountered: