distatus / battery

cross-platform, normalized battery information library
MIT License
249 stars 36 forks source link

Errors() +performance : using strings.Builder instead of string concatenation #31

Open manisharma opened 1 year ago

manisharma commented 1 year ago

Proposing to use strings.Builder in place of string concatenation, in battery.Error() - following are the results -

╭─manish@console.local ~/workspace/battery  ‹master› 
╰─➤  go test -bench=. -benchtime 2s -count 1 -benchmem -cpu 4 -run notest
goos: darwin
goarch: arm64
pkg: github.com/distatus/battery
BenchmarkErrors_Error-4                 14642497               147.5 ns/op            64 B/op          6 allocs/op
BenchmarkErrors_ErrorBuilder-4          37910373                63.16 ns/op           24 B/op          2 allocs/op
PASS
ok      github.com/distatus/battery     4.896s
manisharma commented 1 year ago

Thanks, makes perfect sense to change that. The strings.Builder didn't exist back when I was writing this code.

No need to include 2 versions and benchmarks, though, we're not a strings building library ;-). Just change the old implementation to the new one.

Done, thanks!