TL, For your results, it's a small increase of 1.9%.
For my results, it's a small decrease of −2.03%. $ go version go version devel +232991e Wed Dec 14 05:51:01 2016 +0000 linux/amd64 $ go test -bench=. BenchmarkMemclr_100-4 20000000 115 ns/op BenchmarkLoop_100-4 5000000 244 ns/op BenchmarkMemclr_1000-4 1000000 1026 ns/op BenchmarkLoop_1000-4 1000000 1387 ns/op BenchmarkMemclr_10000-4 200000 10521 ns/op BenchmarkLoop_10000-4 100000 14285 ns/op BenchmarkMemclr_100000-4 10000 146268 ns/op BenchmarkLoop_100000-4 10000 168871 ns/op BenchmarkMemclr_200000-4 5000 291458 ns/op BenchmarkLoop_200000-4 5000 344252 ns/op BenchmarkMemclr_300000-4 3000 494498 ns/op BenchmarkLoop_300000-4 2000 602575 ns/op BenchmarkMemclr_400000-4 2000 734921 ns/op BenchmarkLoop_400000-4 2000 779482 ns/op BenchmarkMemclr_500000-4 2000 981884 ns/op BenchmarkLoop_500000-4 2000 1008058 ns/op BenchmarkMemclr_1000000-4 1000 2073439 ns/op BenchmarkLoop_1000000-4 1000 2093744 ns/op BenchmarkMemclr_2000000-4 300 3932547 ns/op BenchmarkLoop_2000000-4 300 4132627 ns/op PASS ok tl 34.872s $ Peter On Wednesday, December 14, 2016 at 9:12:08 AM UTC-5, T L wrote: > > I just read this issue thread: https://github.com/golang/go/issues/5373 > and this https://codereview.appspot.com/137880043 > which says: > > for i := range a { > a[i] = [zero val] > } > > will be replaced with memclr. > I made some benchmarks, but the results are disappointing. > When the length of slice/array is very large, memclr is slower. > > Result > > BenchmarkMemclr_100-4 100000000 37.2 ns/op > BenchmarkLoop_100-4 100000000 70.7 ns/op > BenchmarkMemclr_1000-4 20000000 351 ns/op > BenchmarkLoop_1000-4 10000000 464 ns/op > BenchmarkMemclr_10000-4 1000000 3623 ns/op > BenchmarkLoop_10000-4 1000000 4940 ns/op > BenchmarkMemclr_100000-4 100000 49230 ns/op > BenchmarkLoop_100000-4 100000 58761 ns/op > BenchmarkMemclr_200000-4 50000 98165 ns/op > BenchmarkLoop_200000-4 50000 115833 ns/op > BenchmarkMemclr_300000-4 30000 170617 ns/op > BenchmarkLoop_300000-4 20000 190193 ns/op > BenchmarkMemclr_400000-4 20000 275676 ns/op > BenchmarkLoop_400000-4 20000 288729 ns/op > BenchmarkMemclr_500000-4 10000 410280 ns/op > BenchmarkLoop_500000-4 10000 416195 ns/op > BenchmarkMemclr_1000000-4 5000 1025504 ns/op > BenchmarkLoop_1000000-4 5000 1012198 ns/op > BenchmarkMemclr_2000000-4 2000 2071861 ns/op > BenchmarkLoop_2000000-4 2000 2032703 ns/op > > test code: > > package main > > import "testing" > > func memclr(a []int) { > for i := range a { > a[i] = 0 > } > } > > func memsetLoop(a []int, v int) { > for i := range a { > a[i] = v > } > } > > var i = 0 > > func BenchmarkMemclr_100(b *testing.B) { > var a = make([]int, 100) > b.ResetTimer() > for i := 0; i < b.N; i++ { > memclr(a) > } > } > > func BenchmarkLoop_100(b *testing.B) { > var a = make([]int, 100) > b.ResetTimer() > for i := 0; i < b.N; i++ { > memsetLoop(a, i) > } > } > > func BenchmarkMemclr_1000(b *testing.B) { > var a = make([]int, 1000) > b.ResetTimer() > for i := 0; i < b.N; i++ { > memclr(a) > } > } > > func BenchmarkLoop_1000(b *testing.B) { > var a = make([]int, 1000) > b.ResetTimer() > for i := 0; i < b.N; i++ { > memsetLoop(a, i) > } > } > > func BenchmarkMemclr_10000(b *testing.B) { > var a = make([]int, 10000) > b.ResetTimer() > for i := 0; i < b.N; i++ { > memclr(a) > } > } > > func BenchmarkLoop_10000(b *testing.B) { > var a = make([]int, 10000) > b.ResetTimer() > for i := 0; i < b.N; i++ { > memsetLoop(a, i) > } > } > > func BenchmarkMemclr_100000(b *testing.B) { > var a = make([]int, 100000) > b.ResetTimer() > for i := 0; i < b.N; i++ { > memclr(a) > } > } > > func BenchmarkLoop_100000(b *testing.B) { > var a = make([]int, 100000) > b.ResetTimer() > for i := 0; i < b.N; i++ { > memsetLoop(a, i) > } > } > > func BenchmarkMemclr_200000(b *testing.B) { > var a = make([]int, 200000) > b.ResetTimer() > for i := 0; i < b.N; i++ { > memclr(a) > } > } > > func BenchmarkLoop_200000(b *testing.B) { > var a = make([]int, 200000) > b.ResetTimer() > for i := 0; i < b.N; i++ { > memsetLoop(a, i) > } > } > > func BenchmarkMemclr_300000(b *testing.B) { > var a = make([]int, 300000) > b.ResetTimer() > for i := 0; i < b.N; i++ { > memclr(a) > } > } > > func BenchmarkLoop_300000(b *testing.B) { > var a = make([]int, 300000) > b.ResetTimer() > for i := 0; i < b.N; i++ { > memsetLoop(a, i) > } > } > > func BenchmarkMemclr_400000(b *testing.B) { > var a = make([]int, 400000) > b.ResetTimer() > for i := 0; i < b.N; i++ { > memclr(a) > } > } > > func BenchmarkLoop_400000(b *testing.B) { > var a = make([]int, 400000) > b.ResetTimer() > for i := 0; i < b.N; i++ { > memsetLoop(a, i) > } > } > > func BenchmarkMemclr_500000(b *testing.B) { > var a = make([]int, 500000) > b.ResetTimer() > for i := 0; i < b.N; i++ { > memclr(a) > } > } > > func BenchmarkLoop_500000(b *testing.B) { > var a = make([]int, 500000) > b.ResetTimer() > for i := 0; i < b.N; i++ { > memsetLoop(a, i) > } > } > > func BenchmarkMemclr_1000000(b *testing.B) { > var a = make([]int, 1000000) > b.ResetTimer() > for i := 0; i < b.N; i++ { > memclr(a) > } > } > > func BenchmarkLoop_1000000(b *testing.B) { > var a = make([]int, 1000000) > b.ResetTimer() > for i := 0; i < b.N; i++ { > memsetLoop(a, i) > } > } > > func BenchmarkMemclr_2000000(b *testing.B) { > var a = make([]int, 2000000) > b.ResetTimer() > for i := 0; i < b.N; i++ { > memclr(a) > } > } > > func BenchmarkLoop_2000000(b *testing.B) { > var a = make([]int, 2000000) > b.ResetTimer() > for i := 0; i < b.N; i++ { > memsetLoop(a, i) > } > } > > > > > -- 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.