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.
BenchmarkDotNet是此类微基准测试的黄金标准。
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. :)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.