From a theoretical point of view, the second example is linear time, and the first may be quadratic time (among the substrings), depending on the implementation.
To determine if this will be the case with your implementation, you will have to look at the source code and (because the compiler can optimize the subject) machine code.
In short, the reasons that depend on the implementation, and in general, to determine the "fastest", you have no choice but MEASURE . Causes can act as heuristic recommendations. But thatβs it: in the end it measures reality, which matters.
source share