How to check elapsed milliseconds using Thread.Sleep in for loop with VB.NET

1 Answer

0 votes
Imports System
Imports System.Diagnostics
Imports System.Threading

Class Program
    Private Shared Sub testSpeed(ByVal ms As Integer)
        Dim stopwatch As Stopwatch = New Stopwatch()
        stopwatch.Start()

        For i As Integer = 0 To 1000 - 1
            Thread.Sleep(ms)
        Next

        stopwatch.[Stop]()
        Console.WriteLine($"Executed in {stopwatch.ElapsedMilliseconds} ms")
    End Sub

    Public Shared Sub Main()
        testSpeed(1)
    End Sub
End Class

 
 
' run:
'
' Executed in 1068 ms
'

 



answered Jul 9 by avibootz

Related questions

1 answer 83 views
83 views asked Sep 1, 2024 by avibootz
1 answer 151 views
1 answer 167 views
1 answer 73 views
1 answer 113 views
...