Sudoku time faults

I wrote a Sudoku puzzle using brute force recursion. Now I wanted to see how long it would take to solve 10 puzzles of these types. So, I created a folder called easy and placed 10 "simple" puzzles in a folder. When I run the solver, the first time it can take 171 ms, the second time it takes 37 ms, and the third 16 ms. Why is there a different time to solve the same problems again? Shouldn't time be consistent?

The second problem is that it only displays the last puzzle, even if I tell it to repaint the screen after loading the puzzle and again after solving it. If I load only one puzzle without solving it, it will show the initial state of the puzzle. If I then call the Solve method, the final solution will be displayed. Here is my method that solves a few puzzles.

void LoadFolderAndSolve() throws FileNotFoundException {

    String folderName = JOptionPane.showInputDialog("Enter folder name");
    long startTime = System.currentTimeMillis();

    for (int i = 1; i < 11; i++) {
        String fileName = folderName + "/puzzle" + i + ".txt";
        ReadPuzzle(filename);  // this has a call to repaint to show the initial puzzle
        SolvePuzzle();         // this has a call to repaint to show the solution
        // If I put something to delay here, puzzle 1-9 is still not shown only 10.
    }

    long finishTime = System.currentTimeMillis();
    long difference = finishTime - startTime;

    System.out.println("Time in ms - " + difference);
}
+4
source share
1 answer

JVM , , .. - . , JVM " ", , .

, , , "" .

+3

Source: https://habr.com/ru/post/1524415/


All Articles