Skip to content

Instantly share code, notes, and snippets.

@aholmes
Created October 11, 2022 00:22
Show Gist options
  • Save aholmes/a42a89486d960251163f514b9cfb2600 to your computer and use it in GitHub Desktop.
Save aholmes/a42a89486d960251163f514b9cfb2600 to your computer and use it in GitHub Desktop.
Roslyn parser timing
void Main()
{
var file = @"path to file";
var sw = new Stopwatch();
sw.Start();
var fileContent = File.ReadAllText(file);
sw.Stop();
Console.WriteLine($"Time to read file: {sw.Elapsed.TotalMilliseconds}ms");
const int iterations = 10000;
var avgs = 0L;
var sw2 = new Stopwatch();
sw2.Start();
for (var i = 0; i < iterations; i++)
{
sw.Restart();
var parsedContent = CSharpSyntaxTree.ParseText(fileContent);
sw.Stop();
avgs += sw.ElapsedTicks;
//Console.WriteLine($"Time to parse file: {sw.ElapsedMilliseconds}ms");
}
sw2.Stop();
Console.WriteLine($"Average parse time {sw.Elapsed.TotalMilliseconds}ms");
Console.WriteLine($"Total for {iterations}: {sw2.Elapsed.TotalSeconds}s");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment