A benchmark of three C++ open source callback/signal/slot libraries -- CppCallback, libsigc++, and boost signal
This is a benchmark comparison of the speed performance of three C++ signal/slot/callback libraries,
CppCallback, libsigc++, and boost::signal2.
The source code of the benchmark is included in the CppCallback package.
|Single slot (callback) benchmark, 100M (100,000,000) iterations. Time unit: milliseconds.|
|Inline member function(E)||VC 9||46||781||766||3547|
|Non-inline member function||VC 9||391||766||781||3515|
|Virtual member function||VC 9||359||719||672||3579|
|global function||VC 9||47||719||734||3578|
|functor object||VC 9||47||468||438||3156|
|Signal(F) (callback list) benchmark, 10M (10,000,000) iterations. Time unit: milliseconds.|
|Invoke empty signal||VC 9||N/A||63||93||2000|
|Invoke signal with 5 slots||VC 9||N/A||641||2734||8797|
|Invoke signal with 10 slots||VC 9||N/A||1109||3328||15203|
|Invoke signal with 50 slots||VC 9||N/A||6735||7875||64813|
Some conclusions based on the data of CppCallback and libsigc++ that compiled with VC:
- For non-inline function, a slot, or a callback, has the same performance level as the native function call. Indeed a slot is only only 50% slower than a native call.
- The slot invoking performance is almost the same between CppCallback and libsigc++.
- A single slot invoking is about equivalent to invoking a normal function via two function pointers, or call a virtual function two times.
- Functor object has the best performance. So always prefer it when possible.
- The slot invoking performance is enough for most purpose usage. 100M iterations only need up to 1000ms, which is average 10ns for a single call. That means if there are 10K slot invoking, only 0.1ms is spent on the invoking itself. 0.1ms is nothing for most high performance games. And don't forget this is the performance on quite old hardware.
- The callback list (signal) performance of CppCallback, for a single slot (note it's 5 slots in a signal in the benchmark) is 50% slower than one single slot call without callback list. That means if there are 10K slot invoking, only 0.2ms is spent on the invoking itself. That also means we can heavily use callbacks (signals) in a 60 FPS game without worrying the impact of the callbacks.
- When there are few slots (callbacks) in a signal (callback list), CppCallback has better performance than libsigc++ because CppCallback has less setup overhead before dispatching. When there are a lot of slots, the performance difference between CppCallback and libsigc++ is trivial.
Reply #3 on : Sun March 03, 2013, 20:24:52
Reply #2 on : Sat April 30, 2011, 22:19:04
Reply #1 on : Sat April 30, 2011, 07:48:34
Write a comment
- Required fields are marked with *
- Security Code is case sensitive, 'A' is different with 'a'.