Skip to content
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

Use a faster method to convert ints to strings #570

Merged
merged 1 commit into from
Jan 9, 2025

Conversation

apocelipes
Copy link
Contributor

"strconv.FormatInt" is faster and does less allocations than "fmt.Sprint". Let's do the right thing with the right tools.

benchmark:

go version 1.23.4

func BenchmarkFmtSprint(b *testing.B) {
	for i := range b.N {
		_ = fmt.Sprint(i)
	}
}

func BenchmarkStrconv(b *testing.B) {
	for i := range b.N {
		strconv.FormatInt(int64(i), 10)
	}
}

image

@boytertesting boytertesting bot added M/complexity Normal or medium complexity M/size Normal or medium sized change labels Jan 8, 2025
@boyter boyter merged commit 11fd9fb into boyter:master Jan 9, 2025
4 checks passed
@apocelipes apocelipes deleted the fast-int-2-str branch January 9, 2025 03:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
M/complexity Normal or medium complexity M/size Normal or medium sized change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants