Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The Problem is first at your Test Code. you used <em>stopwatch.Elapsed.Milliseconds</em> which shows only the milisecond part of the Elapsed time, use <em>TotalMilliseconds</em> to get the whole part...</p> <p>If no exception is thrown, the difference is minimal</p> <p>But the real question is "Do i need to check for exceptions or let C# handle the Exception throwing?"</p> <p>Clearly... handle alone... Try running this:</p> <pre><code>private void TryCatchPerformance() { int iterations = 10000; textBox1.Text = ""; Stopwatch stopwatch = Stopwatch.StartNew(); int c = 0; for (int i = 0; i &lt; iterations; i++) { try { c += i / (i % 50); } catch (Exception) { } } stopwatch.Stop(); Debug.WriteLine(String.Format("With try catch: {0}", stopwatch.Elapsed.TotalSeconds)); Stopwatch stopwatch2 = Stopwatch.StartNew(); int c2 = 0; for (int i = 0; i &lt; iterations; i++) { int iMod50 = (i%50); if(iMod50 &gt; 0) c2 += i / iMod50; } stopwatch2.Stop(); Debug.WriteLine( String.Format("Without try catch: {0}", stopwatch2.Elapsed.TotalSeconds)); } </code></pre> <p>Output: <strong>OBSOLETE : Look below!</strong> With try catch: 1.9938401</p> <p>Without try catch: 8.92E-05</p> <p>Amazing, only 10000 objects, with 200 Exceptions.</p> <p>CORRECTION: I Run my code on DEBUG and VS Written Exception to Output window.. These are the Results of the RELEASE A lot less overhead, but still 7,500 % improvement.</p> <p>With try catch: <strong>0.0546915</strong></p> <p>Checking Alone: <strong>0.0007294</strong></p> <p>With try catch Throwing my own same Exception object: <strong>0.0265229</strong></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload