Reputation: 774
Using Visual Studio 2017.
I have a line of code like this:
EndIndex = TotalPages <= PageButtons ? TotalPages :
Math.Max(PageButtons, Math.Min((PageIndex + pageRange), TotalPages));
How can I can compare this to alternate ways of writing this same code for a result, like:
AltEndIndex = TotalPages <= PageButtons ? TotalPages : (PageButtons > (PageIndex + pageRange) ? PageButtons : (TotalPages < (PageIndex + pageRange) ? TotalPages
: PageIndex + pageRange));
I am about to test that they do actually give the same result, but regardless, there are probably 5 different ways to come to the same result, I am trying to figure out what method is fastest.
Upvotes: 1
Views: 1057
Reputation: 5850
BenchmarkDotNet is the golden standard for microbenchmarks such as this.
Upvotes: 3
Reputation:
You can use the Stopwatch class to create a timer to check ticks.
Stopwatch Code Reference and Examples
Compare one function with the other and use what's faster for you. :)
Upvotes: 0