To measure execution time of a Action in C# and VB.NET you can use the following Extension Method snippet.
Sample C#
public static TimeSpan Time(this Action @this) { var watch = Stopwatch.StartNew(); @this(); watch.Stop(); return watch.Elapsed; }
Sample VB.NET
<System.Runtime.CompilerServices.Extension> _ Public Shared Function Time(this As Action) As TimeSpan Dim watch = Stopwatch.StartNew() this() watch.Stop() Return watch.Elapsed End Function
RT @CodeSnippetsNET: Measure execution time of a Action in C# and #VB .NET http://t.co/NjZ0hducHB #csharp #dotnet