Q:

c# string performance - what is faster to compare, string text or string length

hey guys i have to read a huge xml file which consists of over 3 million records and over 10 million nested elements
naturally i am using xmltextreader and have got my parsing time down to about 40 seconds from earlier 90 seconds using multiple optimization tricks and tips
but i want to further save processing time as much as i can hence below question
quite a few elements are of type xs:boolean and the data provider always represents values as "true" or "false" - never "1" or "0"
for such cases my earliest code was:
if (xmlTextReader.Value == "true")
{
    bool subtitled = true;
}

which i further optimized to:
if (string.Equals(xmlTextReader.Value, "true", StringComparison.OrdinalIgnoreCase))
{
    bool subtitled = true;
}

i wanted to know if below would be fastest (because its either "true" or "false")?
if (xtr.value.length == 4)
{
    bool subtitled = true;
}

A:

Yes, it's faster, because you only compare exactly one value, namely the length of the string.
By comparing two strings with each other, you compare each and every character, as long as both characters are the same. So if you're finding a match for the string "true", you're going to do 4 comparisons before the predicate evaluates to true.
The only problem you have with this solution is, that if someday the value is going to change from true to let's say 1, you're going to run into a problem here.

A:

Comparing length will be faster, but less readable. I wouldn't use it unless I profile the performance of the code and conclude that I need this optimization.

A:

What about comparing the first character to "t"?
Should (maybe :) be faster than comparing the whole string.. 

