Skip to content

Commit 73261b0

Browse files
authored
Merge pull request #139 from isidroas/main
time.process_time() instead of time.clock()
2 parents 275efe0 + 950d989 commit 73261b0

File tree

5 files changed

+12
-12
lines changed

5 files changed

+12
-12
lines changed

ipynb/Palindrome.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@
214214
" self.seen = {}\n",
215215
" self.diff = 0\n",
216216
" self.stack = []\n",
217-
" self.starttime = time.clock()\n",
217+
" self.starttime = time.process_time()\n",
218218
" self.dict = dict\n",
219219
" self.steps = 0\n",
220220
" for word in L.split(','):\n",
@@ -286,7 +286,7 @@
286286
" self.best = len(self)\n",
287287
" self.bestphrase = str(self)\n",
288288
" print('%5d phrases (%5d words) in %3d seconds (%6d steps)' % (\n",
289-
" self.best, self.bestphrase.count(' ')+1, time.clock() - self.starttime,\n",
289+
" self.best, self.bestphrase.count(' ')+1, time.process_time() - self.starttime,\n",
290290
" self.steps))\n",
291291
" assert is_unique_palindrome(self.bestphrase)\n",
292292
"\n",

ipynb/Sudoku IPython Notebook.ipynb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -516,9 +516,9 @@
516516
"def do1(puzzle):\n",
517517
" \"Do one puzzle; showing puzzle and solution and printing elapsed time.\"\n",
518518
" show(puzzle)\n",
519-
" t0 = time.clock()\n",
519+
" t0 = time.process_time()\n",
520520
" solution = solve(Grid(puzzle))\n",
521-
" t1 = time.clock()\n",
521+
" t1 = time.process_time()\n",
522522
" assert is_solution(solution, puzzle)\n",
523523
" show(solution)\n",
524524
" print('{:.3f} seconds'.format(t1 - t0))\n",
@@ -998,9 +998,9 @@
998998
"def benchmark(label, puzzles=puzzles):\n",
999999
" \"Run `solve` on these puzzles; record and verify results for this label; print all results.\"\n",
10001000
" n = len(puzzles)\n",
1001-
" t0 = time.clock()\n",
1001+
" t0 = time.process_time()\n",
10021002
" results = [solve(Grid(p)) for p in puzzles]\n",
1003-
" avg = (time.clock() - t0) / len(puzzles)\n",
1003+
" avg = (time.process_time() - t0) / len(puzzles)\n",
10041004
" for (r, p) in zip(results, puzzles):\n",
10051005
" assert is_solution(r, p) \n",
10061006
" benchmarks[label] = '{:.3f} sec/puzzle ({:.1f} Hz)'.format(avg, 1/avg)\n",

py/pal2.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def __init__(self, L='A man, a plan', R='a canal, Panama', dict=paldict):
127127
## positive for words on left, negative for right.
128128
## .stack holds (action, side, arg) tuples
129129
update(self, left=[], right=[], best=0, seen={}, diff=0, stack=[],
130-
used_reversibles=False, starttime=time.clock(), dict=dict)
130+
used_reversibles=False, starttime=time.process_time(), dict=dict)
131131
for word in L.split(','):
132132
self.add('left', canonical(word))
133133
for rword in reversestr(R).split(','):
@@ -209,7 +209,7 @@ def report(self):
209209
self.best = len(self)
210210
self.bestphrase = str(self)
211211
print('%5d phrases (%5d words) in %3d seconds' % (
212-
self.best, self.bestphrase.count(' ')+1, time.clock() - self.starttime))
212+
self.best, self.bestphrase.count(' ')+1, time.process_time() - self.starttime))
213213
assert is_panama(self.bestphrase)
214214
f = open('pallog%d.txt' % (id(self) % 10000), 'w')
215215
f.write(self.bestphrase + '\n')

py/spell.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def unit_tests():
7979
def spelltest(tests, verbose=False):
8080
"Run correction(wrong) on all (right, wrong) pairs; report results."
8181
import time
82-
start = time.clock()
82+
start = time.process_time()
8383
good, unknown = 0, 0
8484
n = len(tests)
8585
for right, wrong in tests:
@@ -90,7 +90,7 @@ def spelltest(tests, verbose=False):
9090
if verbose:
9191
print('correction({}) => {} ({}); expected {} ({})'
9292
.format(wrong, w, WORDS[w], right, WORDS[right]))
93-
dt = time.clock() - start
93+
dt = time.process_time() - start
9494
print('{:.0%} of {} correct ({:.0%} unknown) at {:.0f} words per second '
9595
.format(good / n, n, unknown / n, n / dt))
9696

py/sudoku.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,9 @@ def solve_all(grids, name=''):
138138
sum(results), N, name, sum(times)/N, N/sum(times), max(times)))
139139

140140
def time_solve(grid):
141-
start = time.clock()
141+
start = time.process_time()
142142
values = solve(grid)
143-
t = time.clock()-start
143+
t = time.process_time()-start
144144
return (t, solved(values))
145145

146146
def solved(values):

0 commit comments

Comments
 (0)