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

6
.gitignore vendored
View File

@@ -1,3 +1,5 @@
*.csv
# ---> Python
# Byte-compiled / optimized / DLL files
__pycache__/
@@ -158,6 +160,4 @@ cython_debug/
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# 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.
#.idea/
.csv
#.idea/

View File

@@ -1,6 +1,8 @@
import pandas as pd
import numpy as np
from random import randrange
import os
import time
from sudoku import sudoku_grid
def load_quiz(df, row):
@@ -17,22 +19,23 @@ def sol_to_string(solution):
return string
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')
for row in range(len(df)):
start = time.time()
for row in range(number_of_runs):
# for row in range(100):
(quiz, string) = load_quiz(df, row)
f.write(f'{string},')
sudoku = sudoku_grid(quiz)
# print(sudoku)
while not sudoku.is_solved():
sudoku.iterate()
# print(f'Iteration {sudoku.iteration}')
# print(sudoku)
solution = sudoku.cleanup()
string = sol_to_string(solution)
f.write(f'{string}\n')
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)')