Skip to content

Commit

Permalink
validate.py: Replace deprecated time.clock() calls (eiffel-community#251
Browse files Browse the repository at this point in the history
)

time.clock() is deprecated and removed in Python 3.8. It was replaced
by time.process_time() and time.perf_counter() in Python 3.3. Replace
the calls in examples/validate.py with time.perf_counter(). This drops
support for Python 2 so the shebang is adjusted (not that the shebang
is very useful for this non-executable file).

This also fixes what probably was an unintentional buglet; on Linux
time.clock() returned the elapsed CPU time but on Windows it returned
the elapsed time. Since the number was seemingly used to report the
validation progress every five seconds the behavior was only correct
on Windows.
  • Loading branch information
magnusbaeck authored and e-backmark-ericsson committed Apr 13, 2022
1 parent ebcdf64 commit 23c03de
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions examples/validate.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3

# Copyright 2017 Ericsson AB.
# For a full list of individual contributors, please see the commit history.
Expand Down Expand Up @@ -90,7 +90,7 @@ def validateExamples(examples, schemas, maxExamples, shuffle):
unchecked = []

numChecked = 0
latestReportTime = time.clock()
latestReportTime = time.perf_counter()

if shuffle:
random.shuffle(examples)
Expand All @@ -111,9 +111,9 @@ def validateExamples(examples, schemas, maxExamples, shuffle):
print("Reached limit of " + str(maxExamples) + " examples to validate. Breaking.")
break

if time.clock() - latestReportTime > 5:
if time.perf_counter() - latestReportTime > 5:
print("Checked " + str(numChecked) + " / " + str(len(examples)) + " examples.", flush=True)
latestReportTime = time.clock()
latestReportTime = time.perf_counter()

return failures, unchecked, numberOfSuccessfulValidations

Expand Down

0 comments on commit 23c03de

Please sign in to comment.