Last active
October 26, 2017 21:42
-
-
Save musoftware/66502a6634f634b522c746a4c9c0c4b9 to your computer and use it in GitHub Desktop.
AverageValues Calc Best Result
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
| public class AverageValues | |
| { | |
| public int intialValue { get; private set; } | |
| public int currentValue = 0; | |
| double oldResult = 0; | |
| bool StopIncrease = false; | |
| int incrementValue = 0; | |
| public AverageValues(int intialValue = 100, int incrementValue = 10) | |
| { | |
| this.intialValue = intialValue; | |
| currentValue = intialValue; | |
| this.incrementValue = incrementValue; | |
| } | |
| public void CalcAverage(Func<int, int> action) | |
| { | |
| Stopwatch stopw = new Stopwatch(); | |
| stopw.Start(); | |
| var result = action.Invoke(currentValue); | |
| stopw.Stop(); | |
| double calcResult = (double)result / stopw.Elapsed.TotalSeconds; | |
| if (oldResult < calcResult) | |
| { | |
| if (StopIncrease) return; | |
| currentValue += 10; | |
| oldResult = calcResult; | |
| } | |
| else | |
| { | |
| currentValue -= 10; | |
| StopIncrease = true; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment