FAQ

On Tuesday, March 5, 2013 12:39:24 PM UTC-6, minux wrote:
On Wed, Mar 6, 2013 at 1:05 AM, davy zhang wrote:
fmt.Sprintf is slow when cast int to string like "%d"
Is there any chance to make it faster?

or there's any faster way to cast int to string?

strconv is even slower ....
Did you read the source of this benchmark? how did you come to this
conclusion?
Note: the result doesn't mean strconv.FormatInt needs 7852ns to format
one integer.
strconv.FormatInt should be much faster than fmt.Sprintf("%d", i).
go test -test.bench "FormatInt"
BenchmarkFormatInt 200000 7852 ns/op
If you really care about performance, you shouldn't use string at all,
you'd
better use []byte and strconv.AppendInt to avoid generating garbage for
strings.
Is the speed of Sprintf / strconv.* a real issue?
Are you doing a good bit of string generation?

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 3 of 12 | next ›
Discussion Overview
groupgolang-nuts @
categoriesgo
postedMar 5, '13 at 5:06p
activeMar 6, '13 at 3:16a
posts12
users5
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase