Click here to Skip to main content
15,902,492 members

Comments by mfp labs (Top 1 by date)

mfp labs 2-Dec-16 6:28am View    
hehehe - as alwayws - code 'matures' while writing :-)
After starting with the regex implementation I thought, testing the performance diffs between direct string massage and regex would be a good idea.
Sharing the findings did sound like a good idea to me.

Btw. - Output
Measure1: "[ ][ ][ ][tab][tab][ ][tab]Hello,[ ]world!".Replace("[tab]", "[ ][ ][ ][ ]") -> 2 ms (10000 iterations)
"[ ][ ][ ][tab][tab][ ][tab]Hello,[ ]world!" nuked to "[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]Hello,[ ]world!"

Measure1: Regex.Replace("[ ][ ][ ][tab][tab][ ][tab]Hello,[ ]world!", "[tab]", "[ ][ ][ ][ ]") -> 16 ms (10000 iterations)
"[ ][ ][ ][tab][tab][ ][tab]Hello,[ ]world!" nuked to "[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]Hello,[ ]world!"

String.Replace is ~8 times faster than Regex.Replace!

press any key to exit

All the best
Michael