29 lines
652 B
C#
29 lines
652 B
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Diagnostics;
|
|
|
|
namespace System.Diagnostics
|
|
{
|
|
public static class StopwatchExtensions
|
|
{
|
|
public static long Time(this Stopwatch sw, Action action, int iterations)
|
|
{
|
|
sw.Reset();
|
|
sw.Start();
|
|
for (int i = 0; i < iterations; i++)
|
|
{
|
|
action();
|
|
}
|
|
sw.Stop();
|
|
|
|
return sw.ElapsedMilliseconds;
|
|
}
|
|
|
|
public static long Time(this Stopwatch sw, Action action)
|
|
{
|
|
return Time(sw, action, 1);
|
|
}
|
|
}
|
|
}
|