Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

One possible reason for the slower performance of C++ lambda functions when called multiple times is the overhead of capturing variables. When a lambda captures variables, the compiler generates code to create a closure object and copy the captured variables into it. This overhead can add extra instructions and memory accesses that may slow down the execution of the lambda compared to a regular function that does not capture variables.

Additionally, the use of lambda functions may also incur additional cache misses and branch mispredictions, depending on how they are used and how frequently they are called. These factors can also contribute to slower performance compared to regular functions.