FAQ

On Mar 5, 2013 8:59 PM, "davy zhang" wrote:
Very interesting, I am using the release version of go 1.0.3 with
mackbookpro i7 2.66Ghz
the result is of BenchmarkRenderTime is way tooooo different :D

I check it on my linux server amazon aws

BenchmarkFmt 1000000 1950 ns/op
BenchmarkRenderTime 500000 4929 ns/op
BenchmarkRenderTimeManual 500000 3379 ns/op
BenchmarkFormatInt 10000000 232 ns/op
BenchmarkAppendInt 20000000 110 ns/op
BenchmarkSprint 1000000 6347 ns/op
BenchmarkSprintf 200000 6493 ns/op

code here :
http://play.golang.org/p/37ZJIZUKfn

which version of go do you use?
I bet he uses tip and you shouldn't benchmark on virtual servers like
amazon aws. Benchmark on a dedicated machine with next to nothing running
for the best results.
On Wed, Mar 6, 2013 at 10:45 AM, Dave Cheney wrote:

Hmm, Fmt.Sprintf appears to be the fastest in your example, but only
the second fastest on my machine.

I am deliberately ignoring your C wrapper, because, IMO, if you wanted
to write C, you should use C, not Go.

results from running linux/amd64 somewhere near tip.

lucky(~/src/tyme) % go test -bench=.
testing: warning: no tests to run
PASS
BenchmarkFmt 2000000 823 ns/op
BenchmarkRenderTime 5000000 572 ns/op
BenchmarkRenderTimeManual 1000000 1594 ns/op

On Wed, Mar 6, 2013 at 1:31 PM, davy zhang wrote:
here is the test code
http://play.golang.org/p/hn6fRpxhRE

here is the cfmt wrapper which didn't offer much speed
http://play.golang.org/p/IQY80LRJWq

I got the result:
BenchmarkCFmtYear 1000000 1125 ns/op
BenchmarkFmt 1000000 1614 ns/op
BenchmarkRenderTime 500000 3881 ns/op
BenchmarkRenderTimeManual 1000000 2664 ns/op

as the fmt's part add the time used will significantly rise

I am doing a log job in my project so the time format is inevitable,
and I
don't want it be a bottle-neck
On Wednesday, March 6, 2013 4:39:42 AM UTC+8, Dave Cheney wrote:

Please supply the code for your benchmark, I will try to reproduce
this
issue.
On Tue, Mar 5, 2013 at 12:05 PM, davy zhang wrote:
fmt.Sprintf is slow when cast int to string like "%d"

I tracked down using pprof, it shows
ROUTINE ====================== fmt.(*operator++).fmtPointer in
/usr/local/go/src/pkg/runtime/print.c
109 934 Total samples (flat / cumulative)
. . 365: void
. . 366: runtime·typestring(Eface e, String s)
. . 367: {
. . 368: s = *e.type->string;
109 934 369: FLUSH(&s);
---
. . 370: }

which kills the performance

Is there any chance to make it faster?

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

strconv is even slower ....


go test -test.bench "FormatInt"

PASS

BenchmarkFormatInt 200000 7852 ns/op

ok strconv 2.636s





--
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...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
--
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.

--
You received this message because you are subscribed to a topic in the
Google Groups "golang-nuts" group.
To unsubscribe from this topic, visit
https://groups.google.com/d/topic/golang-nuts/pN1AtedMX3g/unsubscribe?hl=en-US
.
To unsubscribe from this group and all its topics, send an email to
golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
--
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 | 10 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