Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

time.process_time() instead of time.clock() #139

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ipynb/Palindrome.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
8 changes: 4 additions & 4 deletions ipynb/Sudoku IPython Notebook.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions py/pal2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(','):
Expand Down Expand Up @@ -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')
Expand Down
4 changes: 2 additions & 2 deletions py/spell.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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))

Expand Down
4 changes: 2 additions & 2 deletions py/sudoku.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down