You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Before filing a bug, please check whether it has been fixed since the
latest release. Search the issue tracker and check that you're running the
latest version of Go:
Run "go version" and compare against
http://golang.org/doc/devel/release.html If a newer version of Go exists,
install it and retry what you did to reproduce the problem.
Thanks.
What does 'go version' print?
go version devel +08dcdcdb757b Thu Mar 13 14:04:29 2014 -0700 linux/amd64
What steps reproduce the problem?
I'm attaching a file with benchmarks to illustrate how the optimization can be achieved.
In few words, I'm proposing that loops as this one:
for j := range s {
s[j].X, s[j].Y, s[j].Z = 1, 2, 3
}
could be optimised by the compiler and implemented as:
for j := range s {
p := &s[j]
p.X, p.Y, p.Z = 1, 2, 3
}
What happened?
The unoptimised benchmarks:
BenchmarkLoop 10000 182743 ns/op
BenchmarkLoopLen 10000 170704 ns/op
BenchmarkLoopRange 10000 170395 ns/op
run slower than the optimised ones:
BenchmarkLoopPointer 10000 136950 ns/op
BenchmarkLoopPointerRange 10000 111240 ns/op
What should have happened instead?
Please provide any additional information below.
This optimization is more important that removing bound checks. I've run the benchmarks
with and without bound checks and the effect of this optimization is still important:
$ go test -bench=. loops_test.go
testing: warning: no tests to run
PASS
BenchmarkLoop 10000 182743 ns/op
BenchmarkLoopPointer 10000 136950 ns/op
BenchmarkLoopLen 10000 170704 ns/op
BenchmarkLoopRange 10000 170395 ns/op
BenchmarkLoopPointerRange 10000 111240 ns/op
ok command-line-arguments 7.802s
$ go test -bench=. -gcflags=-B loops_test.go
testing: warning: no tests to run
PASS
BenchmarkLoop 10000 151952 ns/op
BenchmarkLoopPointer 10000 123730 ns/op
BenchmarkLoopLen 10000 134355 ns/op
BenchmarkLoopRange 10000 134049 ns/op
BenchmarkLoopPointerRange 10000 110534 ns/op
ok command-line-arguments 6.620s
by nicolas.riesco:
Attachments:
The text was updated successfully, but these errors were encountered: