Browse files

print the time needed to solving n-queen puzzle

  • Loading branch information...
1 parent 705ec78 commit 3b5f369e4a091f5400f9985cee566bef72f4d5e5 @shenfeng shenfeng committed Feb 13, 2011
Showing with 9 additions and 4 deletions.
  1. +9 −4 src/test/java/jcip/puzzle/QueenPuzzleSolver.java
View
13 src/test/java/jcip/puzzle/QueenPuzzleSolver.java
@@ -32,9 +32,14 @@ public QueenPuzzleSolver(QueenPuzzle puzzle) {
}
public static void main(String[] args) {
- QueenPuzzle puzzle = new QueenPuzzle(26);
- QueenPuzzleSolver solver = new QueenPuzzleSolver(puzzle);
- List<Move> result = solver.solve();
- System.out.println(result);
+ for (int i = 8; i < 100; ++i) {
+ long start = System.currentTimeMillis();
+ QueenPuzzle puzzle = new QueenPuzzle(i);
+ QueenPuzzleSolver solver = new QueenPuzzleSolver(puzzle);
+ List<Move> result = solver.solve();
+ System.out.println("solve problem size of " + i + " takes time "
+ + (System.currentTimeMillis() - start) + " ms; result: "
+ + result);
+ }
}
}

0 comments on commit 3b5f369

Please sign in to comment.