A benchmarking study comparing compile-time and runtime performance of storing C++ lambdas in a std::vector using two approaches: std::function<> and a hand-crafted virtual interface with std::unique_ptr<>. Key findings: std::function<> takes roughly 2-3x longer to compile than the custom interface approach, and with clang++3.6 using emplace_back() with optimizations enabled, compile time explodes to 338 seconds. At runtime, std::function<> is actually faster to call, likely due to better cache locality from small-buffer optimization. emplace_back() provides no meaningful runtime benefit over push_back() in this scenario, and actually hurts compile times significantly.
Table of contents
Setup Copy link Link copied!Compilation performance Copy link Link copied!Populate time Copy link Link copied!Evaluation performance Copy link Link copied!Conclusions Copy link Link copied!Sort: