Skip to content

Instantly share code, notes, and snippets.

@DraTeots
Last active February 26, 2019 10:17
Show Gist options
  • Save DraTeots/5f454968ae84122b526651ad2d6ef2a3 to your computer and use it in GitHub Desktop.
Save DraTeots/5f454968ae84122b526651ad2d6ef2a3 to your computer and use it in GitHub Desktop.
HighResolutionTimer test and profile
// profiling of HighResolutionTimer implementation
// https://gist.github.com/DraTeots/436019368d32007284f8a12f1ba0f545
using System;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Text;
using System.Threading;
namespace HighResolutionTimer
{
class Program
{
private static volatile bool _isFinished;
static void Main(string[] args)
{
Console.WriteLine($"IsHighResolution = {HighResolutionTimer.IsHighResolution}");
Console.WriteLine($"Tick time length = {HighResolutionTimer.TickLength} [ms]");
var stopwatch = new Stopwatch();
int count = 0;
var values = new double[10000]; // The number of repetitions
HighResolutionTimer timer = new HighResolutionTimer(0.5f);
timer.Elapsed += (s, e) =>
{
values[count] = stopwatch.Elapsed.TotalMilliseconds;
stopwatch.Restart();
if (++count == values.Length)
{
timer.Stop();
_isFinished = true;
}
};
stopwatch.Start();
timer.Start();
while (!_isFinished) Thread.Sleep(1); // Just wait for repetitionCount
var tsv = new StringBuilder();
foreach (var value in values)
{
Console.WriteLine(value);
tsv.AppendLine(value.ToString(CultureInfo.InvariantCulture));
}
File.WriteAllText("profile.txt", tsv.ToString());
}
}
}
@DorisLane
Copy link

Hi! I found your content on GitHub and I want to contact you directly. Please, email me on doriss.lane@gmail.com

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment