If a lambda function with captured variables/references is assigned to a std::function, the std::function will, in most cases, allocate space on the heap to store the captured variables (note that some implementations of std::function do not heap-allocate if the size of the captured variable is less than a specific threshold).
This means that not only is there a slight performance penalty due to heap allocation and the execution of std::function but also that it is slower, as heap allocation implies cache misses (more about cache misses in Chapter 4, Data Structures).