C # string performance - which is faster to compare, string text or string length

Hi guys, I have to read a huge xml file, which consists of more than 3 million entries and more than 10 million nested elements.

Naturally, I use xmltextreader and got my syntax time up to about 40 seconds from the earlier 90 seconds, using a few tricks and optimization tips.

but I want to keep processing time as much as possible below the 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 is:

if (xmlTextReader.Value == "true")
{
    bool subtitled = true;
}

which is further optimized for:

if (string.Equals(xmlTextReader.Value, "true", StringComparison.OrdinalIgnoreCase))
{
    bool subtitled = true;
}

, ( "", "" )?

if (xtr.value.length == 4)
{
    bool subtitled = true;
}
+3
7

, , , .

, , . , "true", 4 , true.

, - true, 1, .

+7

, . , , .

+4

"t"?

(:) , .

+3

. , -, , .

- , :

Boolean.TryParse(xmlTextReader.Value, out subtitled)

, , , .

+2

unit test? , , 1000 .

0

"", "", .

:

bool subtitled = (xtr.Value.length == 4);

It should be even faster.

0
source

String comparison and parsing is very slow .Net, I would recommend avoiding the heavy use of parsing / comparison in .Net.

If you are forced to do this, use highly optimized unmanaged or insecure code and use parallelism.

IMHO.

-1
source

Source: https://habr.com/ru/post/1763463/


All Articles