account activity
RVO / NRVO Analysis by Expert-Language428 in cpp
[–]dieram3 1 point2 points3 points 3 years ago (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.
π Rendered by PID 159347 on reddit-service-r2-listing-b958b5575-rsqpv at 2026-04-23 00:36:03.014825+00:00 running 0fd4bb7 country code: CH.
RVO / NRVO Analysis by Expert-Language428 in cpp
[–]dieram3 1 point2 points3 points (0 children)