[go-nuts] Re: About "Declaring Empty Slices" of CodeReviewComments

2017-02-01 Thread T L


On Tuesday, January 31, 2017 at 1:15:40 PM UTC+8, Keiji Yoshida wrote:
>
> Hi,
>
> "Declaring Empty Slices" of CodeReviewComments ( 
> https://github.com/golang/go/wiki/CodeReviewComments#declaring-empty-slices 
> ) says as below:
>
> ```
> When declaring a slice, use
>
> var t []string
>
> rather than
>
> t := []string{}
>
> The former avoids allocating memory if the slice is never appended to.
> ```
>

One of the two "t"s is nil (the first one), the other one is not.
 

>
> I executed a benchmark test against above code but I could not see any 
> difference between them as for the results.
>
> My benchmark test code and its results can be seen here: 
> https://github.com/keijiyoshida/go-code-snippets/blob/master/empty-slice-declaration/main_test.go
>
> Is there something wrong in my benchmark test code or procedure?
>
> Thanks,
> Keiji Yoshida
>

-- 
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: About "Declaring Empty Slices" of CodeReviewComments

2017-02-01 Thread T L


On Tuesday, January 31, 2017 at 1:15:40 PM UTC+8, Keiji Yoshida wrote:
>
> Hi,
>
> "Declaring Empty Slices" of CodeReviewComments ( 
> https://github.com/golang/go/wiki/CodeReviewComments#declaring-empty-slices 
> ) says as below:
>
> ```
> When declaring a slice, use
>
> var t []string
>
> rather than
>
> t := []string{}
>
> The former avoids allocating memory if the slice is never appended to.
> ```
>

One if the two "t"s is nil, the other one is not.
 

>
> I executed a benchmark test against above code but I could not see any 
> difference between them as for the results.
>
> My benchmark test code and its results can be seen here: 
> https://github.com/keijiyoshida/go-code-snippets/blob/master/empty-slice-declaration/main_test.go
>
> Is there something wrong in my benchmark test code or procedure?
>
> Thanks,
> Keiji Yoshida
>

-- 
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: About "Declaring Empty Slices" of CodeReviewComments

2017-01-31 Thread James Bardin
None of those values are escaping or being used. Your only allocation is 
probably the call to fmt.Fprint.

This isn't something that really needs a benchmark, it should be obvious 
that t is nil in `var t []string`, and t is not nil in `t := []string{}`. 
The former doesn't allocate a slice header, while the latter does (though 
it may be in the stack). 



On Tuesday, January 31, 2017 at 12:15:40 AM UTC-5, Keiji Yoshida wrote:
>
> Hi,
>
> "Declaring Empty Slices" of CodeReviewComments ( 
> https://github.com/golang/go/wiki/CodeReviewComments#declaring-empty-slices 
> ) says as below:
>
> ```
> When declaring a slice, use
>
> var t []string
>
> rather than
>
> t := []string{}
>
> The former avoids allocating memory if the slice is never appended to.
> ```
>
> I executed a benchmark test against above code but I could not see any 
> difference between them as for the results.
>
> My benchmark test code and its results can be seen here: 
> https://github.com/keijiyoshida/go-code-snippets/blob/master/empty-slice-declaration/main_test.go
>
> Is there something wrong in my benchmark test code or procedure?
>
> Thanks,
> Keiji Yoshida
>

-- 
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.