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.