Poor performance from too many caught errors?

I have a large C # project (.NET 2.0) that contains very large chunks of code created by SubSonic. Is an attempt like this causing terrible performance?

for (int x = 0; x < identifiers.Count; x++)
        {decimal target = 0;
            try
            {
                target = Convert.ToDecimal(assets[x + identifiers.Count * 2]); // target %
            }
            catch { targetEmpty = true;  }}

What happens if a given field that is transmitted is not something that can be converted to a decimal place, it sets a flag, which is then used later in the record to determine something else.

The problem is that the application literally throws 10,000,000 exceptions, as I parse 30,000 records. The whole process takes almost 10 minutes for everything, and my common goal is to improve this time, and it seemed like a light hanging fruit if its a bad design idea.

Any thoughts would be helpful (be kind, it was a miserable day)

Thank you, Chris

+3
4

, , ( - , ). decimal? TryParse - , , ?

Decimal.TryParse method , , , false:

decimal d;
if (Decimal.TryParse(str, out d)) 
  // Ok, use decimal 'd'
else 
  // Failed - do something else
+5

. . , , , , .

decimal.TryParse , identifiers.Count * 2 ( , )

+4

TryParse . bool, /.

+3

, , .

, , .

Just wait 10 times and check the call stack every time. If the exceptions are a fraction of the time, for example, 50%, then you will see this in the process of throwing or catching them for about a percentage of pauses.

0
source

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


All Articles