code optimization is more or less turned off. I don't know the details of what happens in debug mode, but assume that e.g. Nor was I surprised to see that compiling for debug mode slowed down execution by a factor of approximately 2.5, to around 30 ns/attempt, for all three CPU alternatives. This backtracking core makes no use of libraries or other "external" resources, nothing to slow it down by dotNET overhead. Building for "Any CPU" gave similar timings, which didn't surprise me either: dotNET does a JIT compilation to native code. (If anything surprised me, it would be that it is that fast!). The average time to place a digit and evaluate its validity takes about 11-12 ns. What did not surprise me: Building for x86 or 圆4 does not affect execution time significantly nothing in the code benefits from greater word size. (For the most difficult problem I have found until now, it makes more than 57 million attempts.) To measure its performance I added a counter of how many attempts it makes to place a digit. To illustrate backtracking to a colleague, I wrote a small sudoku solver. Stemp = Console.ReadLine().ToString().ToUpper() Ĭonsole.Write( " \nPlease answer Y or N.") Static public string YesNo( string sPrompt) Static public void DisplayTT(int iFinal)įor ( int iRow = 0 iRow < iFinal.GetLength( 0) iRow )įor ( int iCol = 0 iCol < iFinal.GetLength( 1) iCol ) Static public int GenerateTT( int iValue)įor ( int iRow = 0 iRow < iNum.GetLength( 0) iRow )įor ( int iCol = 0 iCol < iNum.GetLength( 1) iCol ) Static public int GetValue( string s, int iMin, int iMax) While ((YesNo( " Would you like to do another? Y or N:") = " Y")
0 Comments
Leave a Reply. |