From cd1805302c55b247a2046598d5e59b783c8603c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joseph=20Hopfm=C3=BCller?= Date: Fri, 10 Feb 2023 13:40:03 +0100 Subject: [PATCH] add timing --- .gitignore | 6 +++--- solve_many.py | 17 ++++++++++------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index adc58c1..4e90332 100644 --- a/.gitignore +++ b/.gitignore @@ -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 \ No newline at end of file +#.idea/ \ No newline at end of file diff --git a/solve_many.py b/solve_many.py index 3b3025a..952ea95 100644 --- a/solve_many.py +++ b/solve_many.py @@ -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 \ No newline at end of file + 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)') \ No newline at end of file