gossamer icon indicating copy to clipboard operation
gossamer copied to clipboard

refactor: Prefer strconv.Itoa over fmt.Sprint

Open EmilGeorgiev opened this issue 1 year ago • 1 comments

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 avatar May 26 '24 12:05 EmilGeorgiev

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

EmilGeorgiev avatar Jun 08 '24 14:06 EmilGeorgiev