Search code examples
qtsignals-slots

Will signal "broadcast" faster than calling function through for loop?


I'm facing a situation like there are about more than 1k instances of a class, where a method of the class should be called frequently. Since the current implementation is through maintaining a list of the instances and calling the method using a for loop and it hurts the real-time requirement of the application, I'm considering the signal and slot mechanism from Qt.

The question is: if i change the method into a slot and connect it with a signal while the instance got created, and instead of calling the method through a for loop, i emit a signal. Will it be faster than the for-loop solution?


Solution

  • The short answer: No.

    Long answer: You should try and measure it yourself. But I bet that calling a function directly is definitely faster than signal-slot invocation. Why? Because signals and slots are no magic. They are also just function calls but with lots of extra overhead.