try catch performance

前端 未结 7 953
小蘑菇
小蘑菇 2020-11-29 09:28

This article on MSDN states that you can use as many try catch blocks as you want and not incur any performance cost as long no actual exception is thrown.
Since I alway

7条回答
  •  南方客
    南方客 (楼主)
    2020-11-29 09:38

    A difference of just 34 milliseconds is smaller than the margin-of-error for a test like this.

    As you've noticed, when you increase the duration of the test that difference just falls away and the performance of the two sets of code is effectively the same.

    When doing this sort of benchmark I try to loop over each section of code for at least 20 seconds, preferably longer, and ideally for several hours.

提交回复
热议问题