Last active
February 26, 2019 10:17
-
-
Save DraTeots/5f454968ae84122b526651ad2d6ef2a3 to your computer and use it in GitHub Desktop.
HighResolutionTimer test and profile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi! I found your content on GitHub and I want to contact you directly. Please, email me on doriss.lane@gmail.com