when writing a function today, You need to determine whether a string is an XML or a number. When you start with startswith, you can determine whether the string starts with startswith. Later, you find that this function requires high-frequency calls, I don't know if startswith has performance problems. The following Code is written for verification:
var content = "
1
" ; stopwatch Sw = stopwatch. startnew (); for ( int I = 0; I <1000000; I ++) {var r = content. startswith ( "<" );} SW. stop (); console. writeline ( "Test 1:" + SW. elapsedmilliseconds); Sw = stopwatch. startnew (); for ( int I = 0; I <1000000; I ++) {var r = content. startswith ( "
"
);} SW. stop (); console. writeline ( "Test 2:" + SW. elapsedmilliseconds); Sw = stopwatch. startnew (); for ( int I = 0; I <1000000; I ++) {var r = content [0] = ';} SW. stop (); console. writeline ( "Test 3:" + SW. elapsedmilliseconds);
Basically, the first three types of performance are the highest, but the second type should be safe.