Cleanup Ranges and SimpleTime
This commit is contained in:
parent
ff2efca658
commit
abba7fbb78
|
@ -1,13 +1,11 @@
|
||||||
#nullable disable
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
|
|
||||||
using BizHawk.Common.NumberExtensions;
|
|
||||||
|
|
||||||
namespace BizHawk.Common
|
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>
|
/// <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>
|
public struct RangeStruct<T> where T : unmanaged, IComparable<T>
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,31 +1,27 @@
|
||||||
#nullable disable
|
namespace BizHawk.Common
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Diagnostics;
|
|
||||||
|
|
||||||
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
|
public class SimpleTime : IDisposable
|
||||||
{
|
{
|
||||||
private readonly Stopwatch _w;
|
private readonly Action<long> _callback;
|
||||||
private readonly Action<int> _f;
|
|
||||||
|
|
||||||
public SimpleTime(string s)
|
private readonly Stopwatch _stopwatch = new Stopwatch();
|
||||||
: this(t => Console.WriteLine("Elapsed time for {0}: {1}ms", s, t))
|
|
||||||
|
public SimpleTime(Action<long> callback)
|
||||||
{
|
{
|
||||||
|
_callback = callback;
|
||||||
|
_stopwatch.Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
public SimpleTime(Action<int> f)
|
public SimpleTime(string label) : this(l => Console.WriteLine($"Elapsed time for {label}: {l} ms")) {}
|
||||||
{
|
|
||||||
_f = f;
|
|
||||||
_w = new Stopwatch();
|
|
||||||
_w.Start();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
_w.Stop();
|
_stopwatch.Stop();
|
||||||
_f((int)_w.ElapsedMilliseconds);
|
_callback(_stopwatch.ElapsedMilliseconds);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue