Created
October 11, 2022 00:22
-
-
Save aholmes/a42a89486d960251163f514b9cfb2600 to your computer and use it in GitHub Desktop.
Roslyn parser timing
This file contains hidden or 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
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