Timing Sections of .Net Code

Anonymous
2021-06-11T10:42:43.493+00:00

Using Visual Studio 2019, VB .Net.

Looking for the best way to time sections of code to find a the exact code causing new delays running a command.
These are applications on client workstations running against a a SQL Server database.

I did some tracing and profiling MANY years ago, but wondering if there's a better way today. I want to have minimal to no impact on client performance, while running these checks, if possible, or get a feel for anticipated performance impact.

If there is a significant impact, the quicker I can disable the timing checks, the better.

Developer technologies | VB
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Dewayne Basnett 1,381 Reputation points
    2021-06-11T13:22:54.483+00:00

    Use a StopWatch. A quick example.

            Dim stpw As New Stopwatch  
      
            'code to time  
            stpw.Restart()  
            For x As Integer = 1 To 1000000  
                Dim i As Integer = x  
            Next  
      
            'timing done  
            stpw.Stop()  
            Debug.WriteLine(stpw.Elapsed)  
      
    

  2. Karen Payne MVP 35,586 Reputation points Volunteer Moderator
    2021-06-11T16:19:50.207+00:00

    Hello,

    Working also with a StopWatch as @Dewayne Basnett check out the following code sample on GitHub.

    Provides

    • Access to a StopWatch using a singleton which means you can all functionality any place in your project
    • Option to write to comma delimited file

    There is plenty of room for customization.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.