On Saturday, February 11, 2017 at 1:49:58 PM UTC+8, T L wrote:
>
> https://github.com/golang/go/issues/5373
>
btw, does this optimization imply that the zero value of any type is
composed by zero bytes?
At least for all current supported ARCHes.
>
>
> I made a test
>
> package main
>
> import (
> "testing"
> )
>
> const N = 1024 * 100
> var a [N]int
>
> func BenchmarkArrayPtr(b *testing.B) {
> for i := 0; i < b.N; i++ {
> for i := range &a {
> a[i] = 0
> }
> }
> }
>
> func BenchmarkArray(b *testing.B) {
> for i := 0; i < b.N; i++ {
> for i := range a {
> a[i] = 0
> }
> }
> }
>
> func BenchmarkArrayB(b *testing.B) {
> var k int
> go func() {
> k = 123
> }()
> for i := 0; i < b.N; i++ {
> for k = range a {
> a[k] = 0
> }
> }
> }
>
> /*
> Outputs:
> BenchmarkArrayPtr-4 50000 90457 ns/op
> BenchmarkArray-4 100000 49656 ns/op
> BenchmarkArrayB-4 100000 49628 ns/op
> */
>
> it looks the loop in the BenchmarkArrayB is also optimized as a memclr
> call, but I can't make sure it is true.
> If it is true, it is over-optimized.
> Anyone can confirm it is over-optimized or not?
>
--
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 [email protected].
For more options, visit https://groups.google.com/d/optout.