I have a very long string (60MB in size) in which I need to find how many pairs of \'<\' and \'>\' are in there.
I have first tried my own way:
I would expect string.IndexOf
compared to your first code sample to run at least twice as fast (besides any other optimizations that might be done there) since you check for both start and end character in each of your iterations. Your implementation with string.IndexOf
on the other hand will check for the end character only after it has successfully found a start character. This cuts the number of operations on each iteration down significantly (one less comparison).