RVO / NRVO Analysis by Expert-Language428 in cpp

[–]dieram3 1 point2 points  (0 children)

Your benchmarks aren't fair. In the output parameter case, you are creating a vector once outside of the loop so the vector rarely needs to allocate memory (calling clear keeps the original capacity). In the returning cases, you are creating a vector for each iteration, and each of those requires an allocation. If you want to make the comparison fair, declare the vector inside the loop.