03.10.2013, 13:29
Quote:
Actually using strcat for that - it IS faster than some other methods which using format which is pretty slow.
|
Sure, scanning one string for input and working on another for output will be incredibly slow most of the time. But with the simplicity of the format used in this case (it just has to check two characters and it knows what to do) and the fact that the function knows where the end of the string is and doesn't have to count it over time, it would mean that over longer strings with more concatenations the format should actually gain efficiency over repeated strcat's which have to count strings of longer and longer lengths repeatedly.
Just a theory but the logic makes sense. I won't go to great lengths to test it now but if I were to be faced with the possibility to use both in a particular situation where optimisation is a must, I would test both methods with my particular code instead of going with the popular belief unless I was certain that one way was better... Even then, who knows, it might just be that under the current circumstances, there is a surprising exception.