Remix.run Logo
LegionMammal978 3 months ago

You can get another 56% speedup on the reserve()+emplace_back() version just by replacing (Widget widget) with (const Widget& widget) in the function declaration [0], more of a difference than any of the loops. As well as a further 39% speedup by moving transformed_data into repsonse.data instead of copying it [1]. My takeaway is that C++ makes it extremely easy to copy data around unnecessarily. Also, you should always profile your code for easy wins before making drastic changes.

[0] https://quick-bench.com/q/1Lcfho3hZW2DVgse3xkn82hZsFg

[1] https://quick-bench.com/q/r0DxLEPK68VhBPect3qAhkNIVnA