BizHawk/BizHawk.Common/SimpleTime.cs

30 lines
503 B
C#
Raw Normal View History

2014-10-09 01:49:44 +00:00
using System;
using System.Diagnostics;
namespace BizHawk.Common
{
public class SimpleTime : IDisposable
{
2017-04-13 18:57:58 +00:00
private readonly Stopwatch _w;
private readonly Action<int> _f;
2014-10-09 01:49:44 +00:00
public SimpleTime(string s)
2017-04-13 18:57:58 +00:00
: this(t => Console.WriteLine("Elapsed time for {0}: {1}ms", s, t))
2014-10-09 01:49:44 +00:00
{
}
public SimpleTime(Action<int> f)
{
2017-04-13 18:57:58 +00:00
_f = f;
_w = new Stopwatch();
_w.Start();
2014-10-09 01:49:44 +00:00
}
public void Dispose()
{
2017-04-13 18:57:58 +00:00
_w.Stop();
_f((int)_w.ElapsedMilliseconds);
2014-10-09 01:49:44 +00:00
}
}
}