I recently came across the same question for a project with similar simple requirements and did some research that I'd like to share here.
My main interest was in the overhead of boost::signals2
compared to a simple vector-of-callback-functions implementation. Finally I did some more research as shown in the following table:
Benchmark Duration (normalized) --------------------------------------------------------------------- Direct function call 1 Function pointer call 1 Virtual function call 1 std::function call 1.5 std::vector<std::function> call 2 boost::signals signal invocation 78 boost::signals2 signal invocation (dummy mutex) 43 boost::signals2 signal invocation 92
The measurements have been taken on a Ubuntu 15.04 with gcc 4.9.2, optimization -O2, Boost v1.55. Because the absolute values might well be meaningless outside of my box the values are normalized. More recent versions of Boost might well be faster.
My conclusion would be: If performance is critical and you don't need thread safety (or other advanced features) reconsider using boost::signals2
.
If you want to reproduce the measures on your machine the code is available here.