add timing

This commit is contained in:
Joseph Hopfmüller
2023-02-10 13:40:03 +01:00
parent da7d4a88f4
commit cd1805302c
2 changed files with 13 additions and 10 deletions

4
.gitignore vendored
View File

@@ -1,3 +1,5 @@
*.csv
# ---> Python # ---> Python
# Byte-compiled / optimized / DLL files # Byte-compiled / optimized / DLL files
__pycache__/ __pycache__/
@@ -159,5 +161,3 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear # and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder. # option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/ #.idea/
.csv

View File

@@ -1,6 +1,8 @@
import pandas as pd import pandas as pd
import numpy as np import numpy as np
from random import randrange from random import randrange
import os
import time
from sudoku import sudoku_grid from sudoku import sudoku_grid
def load_quiz(df, row): def load_quiz(df, row):
@@ -17,22 +19,23 @@ def sol_to_string(solution):
return string return string
df = pd.read_csv('sudoku.csv') df = pd.read_csv('sudoku.csv')
# number_of_runs = len(df)
number_of_runs = 10000
with open('solved.csv', 'a+') as f: with open('solved.csv', 'w') as f:
f.write('quizzes,solutions\n') f.write('quizzes,solutions\n')
for row in range(len(df)): start = time.time()
for row in range(number_of_runs):
# for row in range(100): # for row in range(100):
(quiz, string) = load_quiz(df, row) (quiz, string) = load_quiz(df, row)
f.write(f'{string},') f.write(f'{string},')
sudoku = sudoku_grid(quiz) sudoku = sudoku_grid(quiz)
# print(sudoku)
while not sudoku.is_solved(): while not sudoku.is_solved():
sudoku.iterate() sudoku.iterate()
# print(f'Iteration {sudoku.iteration}')
# print(sudoku)
solution = sudoku.cleanup() solution = sudoku.cleanup()
string = sol_to_string(solution) string = sol_to_string(solution)
f.write(f'{string}\n') f.write(f'{string}\n')
print(f'Sudoku {row} solved!') print(f'Sudoku {row} solved!')
print(sudoku)
del sudoku del sudoku
stop = time.time()
print(f'Solved {number_of_runs} sudokus in {stop-start:.2f}s ({number_of_runs/(stop-start):2f} sudokus/s)')