[go-nuts] Re: Does fmt.Fprint use WriteString ?

2019-04-24 Thread codiglot
That's interesting and good to know. I guess it should be expected given 
that Fprint does a bit more work using it's internal printer struct and 
buffer.

On Tuesday, April 23, 2019 at 1:43:55 PM UTC-4, Constantin Konstantinidis 
wrote:
>
> The result is equivalent but a micro-benchmark shows that pkg io is 3x 
> faster.
>
> go version go1.12.2 windows/amd64
> pkg: github.com/iWdGo/GoCompilerEfficiency/src/writestring
> BenchmarkFmtWriteString-4 
> 
>  50  2002 ns/op
> BenchmarkIoWriteString-4 200   635 ns/op
> PASS
>
>
> This is irrelevant is the string requires some build.
> (sorry for the typo above)
>

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


[go-nuts] Re: Does fmt.Fprint use WriteString ?

2019-04-22 Thread codiglot
Actually, that comment points to the implementation of WriteString for the 
fmt package's internal pp type, which in turn is used by other fmt 
functions to handle strings efficiently. After scanning that source file 
some more, and the source file for io.WriteString (
https://golang.org/src/io/io.go?s=10163:10218#L279) I can see that even 
though fmt.Fprint and others don't use io.WriteString directly, they do 
exactly the same thing io.WriteString does, which is calling the 
destination's Write method exactly once and only once, thus avoiding extra 
allocations. So in conclusion, from what I see, it's equally efficient to 
write a string to a writer via io.WriteString or fmt.Fprint.

On Monday, April 22, 2019 at 9:28:50 AM UTC-4, Constantin Konstantinidis 
wrote:
>
> fmt.Fprint is calling io.WriteString as you can this comment 
> 
>  
> and the code around indicates.
>

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


[go-nuts] Does fmt.Fprint use WriteString ?

2019-04-21 Thread codiglot
Hi gophers! Just wondering if in a Handler I should (w is the 
http.ResponseWriter):

fmt.Fprint(w, "Hello world")

or is it better to 

io.WriteString(w, "Hello world")

or is it the same if fmt.Fprint already uses WriteString internally?

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