diff --git a/ipynb/Palindrome.ipynb b/ipynb/Palindrome.ipynb index 985ca0be..44b7f9f6 100644 --- a/ipynb/Palindrome.ipynb +++ b/ipynb/Palindrome.ipynb @@ -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", diff --git a/ipynb/Sudoku IPython Notebook.ipynb b/ipynb/Sudoku IPython Notebook.ipynb index 6ca53a9b..2154a291 100644 --- a/ipynb/Sudoku IPython Notebook.ipynb +++ b/ipynb/Sudoku IPython Notebook.ipynb @@ -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", diff --git a/py/pal2.py b/py/pal2.py index 4faecb4f..f48b3ace 100644 --- a/py/pal2.py +++ b/py/pal2.py @@ -127,7 +127,7 @@ def __init__(self, L='A man, a plan', R='a canal, Panama', dict=paldict): ## positive for words on left, negative for right. ## .stack holds (action, side, arg) tuples update(self, left=[], right=[], best=0, seen={}, diff=0, stack=[], - used_reversibles=False, starttime=time.clock(), dict=dict) + used_reversibles=False, starttime=time.process_time(), dict=dict) for word in L.split(','): self.add('left', canonical(word)) for rword in reversestr(R).split(','): @@ -209,7 +209,7 @@ def report(self): self.best = len(self) self.bestphrase = str(self) print('%5d phrases (%5d words) in %3d seconds' % ( - self.best, self.bestphrase.count(' ')+1, time.clock() - self.starttime)) + self.best, self.bestphrase.count(' ')+1, time.process_time() - self.starttime)) assert is_panama(self.bestphrase) f = open('pallog%d.txt' % (id(self) % 10000), 'w') f.write(self.bestphrase + '\n') diff --git a/py/spell.py b/py/spell.py index ac37b9b9..6720301b 100644 --- a/py/spell.py +++ b/py/spell.py @@ -79,7 +79,7 @@ def unit_tests(): def spelltest(tests, verbose=False): "Run correction(wrong) on all (right, wrong) pairs; report results." import time - start = time.clock() + start = time.process_time() good, unknown = 0, 0 n = len(tests) for right, wrong in tests: @@ -90,7 +90,7 @@ def spelltest(tests, verbose=False): if verbose: print('correction({}) => {} ({}); expected {} ({})' .format(wrong, w, WORDS[w], right, WORDS[right])) - dt = time.clock() - start + dt = time.process_time() - start print('{:.0%} of {} correct ({:.0%} unknown) at {:.0f} words per second ' .format(good / n, n, unknown / n, n / dt)) diff --git a/py/sudoku.py b/py/sudoku.py index db8b81e3..2b887647 100644 --- a/py/sudoku.py +++ b/py/sudoku.py @@ -138,9 +138,9 @@ def solve_all(grids, name=''): sum(results), N, name, sum(times)/N, N/sum(times), max(times))) def time_solve(grid): - start = time.clock() + start = time.process_time() values = solve(grid) - t = time.clock()-start + t = time.process_time()-start return (t, solved(values)) def solved(values):