
On Wed, Feb 1, 2012 at 10:21 AM, Dave Abrahams <dave@boostpro.com> wrote:
on Tue Jan 31 2012, Ion Gaztañaga <igaztanaga-AT-gmail.com> wrote:
... Although returning vectors by value might be a good idea for factories, and such things, it's always more efficient to pass a reference to a vector, and clear() + fill or assign, or even better, reusing already constructed values (which can be vectors of vectors).
Are there any numbers to back that claim up? It seems obvious at first glance, of course, but sometimes reality surprises us.
I ran such a test a couple of years ago. While I've forgotten the details, it had to do with how to pass back the result of string encoding conversions for shortish strings. Return by value did surprisingly well in the particular application. Between optimizing compilers and aggressive CPU performance optimizations, measurement is the only real way to know which is more efficient. --Beman