ChainSafe / gossamer

🕸️ Go Implementation of the Polkadot Host
https://chainsafe.github.io/gossamer
GNU Lesser General Public License v3.0
427 stars 110 forks source link

refactor: Prefer strconv.Itoa over fmt.Sprint #3981

Open EmilGeorgiev opened 1 month ago

EmilGeorgiev commented 1 month ago

Issue summary

strconv.Itoa is faster than fmt.Sprint and is preferred for converting integers to strings. The example below demonstrates the difference between them.

func BenchmarkStrconv(b *testing.B) {
    for j := 0; j < b.N; j++ {
        _ = strconv.Itoa(80) //BenchmarkStrconv-16      508842183            2.283 ns/op
    }
}

vs

func BenchmarkFMT(b *testing.B) {
    for j := 0; j < b.N; j++ {
        _ = fmt.Sprint(80) // BenchmarkFMT-16       23801236            52.26 ns/op
    }
}
EmilGeorgiev commented 3 weeks ago

If you think this makes sense, can I take this issue?