Cleanup Ranges and SimpleTime

This commit is contained in:
YoshiRulz 2020-01-23 15:53:19 +10:00
parent ff2efca658
commit abba7fbb78
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
2 changed files with 20 additions and 26 deletions

View File

@ -1,13 +1,11 @@
#nullable disable
using System;
using System.Collections.Generic;
using System.Linq;
using BizHawk.Common.NumberExtensions;
namespace BizHawk.Common
{
using System;
using System.Collections.Generic;
using System.Linq;
using BizHawk.Common.NumberExtensions;
/// <summary>semantically similar to <see cref="Range{T}"/>, but obviously does no checks at runtime</summary>
public struct RangeStruct<T> where T : unmanaged, IComparable<T>
{

View File

@ -1,31 +1,27 @@
#nullable disable
using System;
using System.Diagnostics;
namespace BizHawk.Common
namespace BizHawk.Common
{
using System;
using System.Diagnostics;
/// <summary>Create a new instance of this class in a <see langword="using"/> block, and it will measure the time elapsed until the block finishes executing. Provide a label to print to stdout or provide a callback for custom behaviour.</summary>
public class SimpleTime : IDisposable
{
private readonly Stopwatch _w;
private readonly Action<int> _f;
private readonly Action<long> _callback;
public SimpleTime(string s)
: this(t => Console.WriteLine("Elapsed time for {0}: {1}ms", s, t))
private readonly Stopwatch _stopwatch = new Stopwatch();
public SimpleTime(Action<long> callback)
{
_callback = callback;
_stopwatch.Start();
}
public SimpleTime(Action<int> f)
{
_f = f;
_w = new Stopwatch();
_w.Start();
}
public SimpleTime(string label) : this(l => Console.WriteLine($"Elapsed time for {label}: {l} ms")) {}
public void Dispose()
{
_w.Stop();
_f((int)_w.ElapsedMilliseconds);
_stopwatch.Stop();
_callback(_stopwatch.ElapsedMilliseconds);
}
}
}