Merge pull request #139 from isidroas/main

time.process_time() instead of time.clock()
This commit is contained in:
Peter Norvig
2025-05-30 14:09:04 -07:00
committed by GitHub
5 changed files with 12 additions and 12 deletions

View File

@@ -214,7 +214,7 @@
" self.seen = {}\n",
" self.diff = 0\n",
" self.stack = []\n",
" self.starttime = time.clock()\n",
" self.starttime = time.process_time()\n",
" self.dict = dict\n",
" self.steps = 0\n",
" for word in L.split(','):\n",
@@ -286,7 +286,7 @@
" self.best = len(self)\n",
" self.bestphrase = str(self)\n",
" print('%5d phrases (%5d words) in %3d seconds (%6d steps)' % (\n",
" self.best, self.bestphrase.count(' ')+1, time.clock() - self.starttime,\n",
" self.best, self.bestphrase.count(' ')+1, time.process_time() - self.starttime,\n",
" self.steps))\n",
" assert is_unique_palindrome(self.bestphrase)\n",
"\n",

View File

@@ -516,9 +516,9 @@
"def do1(puzzle):\n",
" \"Do one puzzle; showing puzzle and solution and printing elapsed time.\"\n",
" show(puzzle)\n",
" t0 = time.clock()\n",
" t0 = time.process_time()\n",
" solution = solve(Grid(puzzle))\n",
" t1 = time.clock()\n",
" t1 = time.process_time()\n",
" assert is_solution(solution, puzzle)\n",
" show(solution)\n",
" print('{:.3f} seconds'.format(t1 - t0))\n",
@@ -998,9 +998,9 @@
"def benchmark(label, puzzles=puzzles):\n",
" \"Run `solve` on these puzzles; record and verify results for this label; print all results.\"\n",
" n = len(puzzles)\n",
" t0 = time.clock()\n",
" t0 = time.process_time()\n",
" results = [solve(Grid(p)) for p in puzzles]\n",
" avg = (time.clock() - t0) / len(puzzles)\n",
" avg = (time.process_time() - t0) / len(puzzles)\n",
" for (r, p) in zip(results, puzzles):\n",
" assert is_solution(r, p) \n",
" benchmarks[label] = '{:.3f} sec/puzzle ({:.1f} Hz)'.format(avg, 1/avg)\n",