for i := range &array

103 views
Skip to first unread message

Vadim Maximov

unread,
Aug 16, 2019, 1:11:17 PM8/16/19
to golang-nuts
Hi, all!

Is for...range over an address/reference of  an array faster than regular for...range? For instance:

arr :=[...]int{1,2,3}
for _,v := range &arr{
   fmt
.Println(v)
}

I heard that it  is slightly faster for huge arrays, but why is it so? And is it actually true (or makes sense)?

Jan Mercl

unread,
Aug 16, 2019, 1:32:35 PM8/16/19
to Vadim Maximov, golang-nuts
One ranges a copy of the array, the other does not: https://play.golang.org/p/Z3InmyFqQN3

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/33c85347-6b48-4e74-9718-15d5b7317f93%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages