FAQ
Hello

I found that using value-type named return variables in an outer function
incurs a performance penalty even if it does nothing with those variables
and only calls the inner function.

The benchmark code is here: http://play.golang.org/p/-Dp4oeHd3k

# go test -bench=Outer nrv
BenchmarkSlowOuter 50000000 38.6 ns/op
BenchmarkFastOuter 50000000 27.7 ns/op

// disabled inlining
# GCFLAGS="-l" go test -bench=Outer nrv
BenchmarkSlowOuter 50000000 39.0 ns/op
BenchmarkFastOuter 50000000 28.0 ns/op

// disabled inlining and 'optimizations'
# GCFLAGS="-l -N" go test -bench=Outer nrv
BenchmarkSlowOuter 50000000 39.0 ns/op
BenchmarkFastOuter 100000000 28.0 ns/op

My guess is that we instantiate the value struct, even though it isn't
touched in the outer function.

--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

Discussion Posts

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 1 of 5 | next ›
Discussion Overview
groupgolang-nuts @
categoriesgo
postedJan 31, '13 at 2:48p
activeFeb 3, '13 at 5:35p
posts5
users4
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase