aoc2021/aoc2021/Extensions.cs

27 lines
917 B
C#
Raw Normal View History

2021-11-11 05:19:35 +00:00
namespace aoc2021;
public static class Extensions
{
/// <summary>
/// increased accuracy for stopwatch based on frequency.
/// <see
/// href="http://geekswithblogs.net/BlackRabbitCoder/archive/2012/01/12/c.net-little-pitfalls-stopwatch-ticks-are-not-timespan-ticks.aspx">
/// blog
/// details here
/// </see>
/// </summary>
/// <param name="stopwatch"></param>
/// <returns></returns>
public static double ScaleMilliseconds(this Stopwatch stopwatch) =>
1_000 * stopwatch.ElapsedTicks / (double)Stopwatch.Frequency;
2021-11-11 05:19:35 +00:00
/// <summary>
/// Does a <see cref="Range"/> include a given int?
/// </summary>
/// <param name="range"></param>
/// <param name="i"></param>
/// <returns></returns>
public static bool Contains(this Range range, int i) =>
i >= range.Start.Value && i <= range.End.Value;
2021-11-11 05:19:35 +00:00
}