C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
VB.NET program that calls Math.Sqrt
Module Module1
Sub Main()
Dim result1 As Double = Math.Sqrt(1)
Dim result2 As Double = Math.Sqrt(2)
Dim result3 As Double = Math.Sqrt(3)
Dim result4 As Double = Math.Sqrt(4)
Console.WriteLine(result1)
Console.WriteLine(result2)
Console.WriteLine(result3)
Console.WriteLine(result4)
End Sub
End Module
Output
1
1.4142135623731
1.73205080756888
2
Implementation of Sqrt: IL
.method public hidebysig static float64 Sqrt(float64 d) cil managed internalcall
{
} // end of method Math::Sqrt
Tip: The performance of Math.Sqrt largely depends on what arguments you pass to it.
BenchmarksVB.NET program that times Math.Sqrt
Module Module1
Sub Main()
Dim m As Integer = 10000000
Dim s1 As Stopwatch = Stopwatch.StartNew
For i As Integer = 0 To m - 1
If Math.Sqrt(4) = 1 Then
Throw New Exception
End If
Next
s1.Stop()
Dim s2 As Stopwatch = Stopwatch.StartNew
For i As Integer = 0 To m - 1
If Math.Sqrt(4.1) = 1 Then
Throw New Exception
End If
Next
s2.Stop()
Dim u As Integer = 1000000
Console.WriteLine(((s1.Elapsed.TotalMilliseconds * u) / m).ToString("0.00 ns"))
Console.WriteLine(((s2.Elapsed.TotalMilliseconds * u) / m).ToString("0.00 ns"))
End Sub
End Module
Output
2.61 ns
6.20 ns