Skip to content

Commit 3a67156

Browse files
committed
Replace time.clock() with time.perf_counter() in slowsquare examples
Fixes #1757 time.clock() was removed in Python 3.8 in favor of time.perf_counter(). This commit updates the slowsquare RPC examples to use the modern API. Changes: - examples/twisted/wamp/rpc/slowsquare/frontend.py: 3 replacements - examples/asyncio/wamp/rpc/slowsquare/frontend.py: 3 replacements time.perf_counter() provides a monotonic clock with the best available resolution for measuring performance, which is the intended behavior for timing RPC call durations. Tested with: just test-integration-ab-examples from crossbar repository
1 parent 97b34a9 commit 3a67156

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

examples/asyncio/wamp/rpc/slowsquare/frontend.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ class Component(ApplicationSession):
4040
async def onJoin(self, details):
4141
def got(started, msg, f):
4242
res = f.result()
43-
duration = 1000.0 * (time.clock() - started)
43+
duration = 1000.0 * (time.perf_counter() - started)
4444
print("{}: {} in {}".format(msg, res, duration))
4545

46-
t1 = time.clock()
46+
t1 = time.perf_counter()
4747
d1 = self.call("com.math.slowsquare", 3, 2)
4848
d1.add_done_callback(partial(got, t1, "Slow Square"))
4949

50-
t2 = time.clock()
50+
t2 = time.perf_counter()
5151
d2 = self.call("com.math.square", 3)
5252
d2.add_done_callback(partial(got, t2, "Quick Square"))
5353

examples/twisted/wamp/rpc/slowsquare/frontend.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ def onJoin(self, details):
4141
print("session attached")
4242

4343
def got(res, started, msg):
44-
duration = 1000.0 * (time.clock() - started)
44+
duration = 1000.0 * (time.perf_counter() - started)
4545
print("{}: {} in {}".format(msg, res, duration))
4646

47-
t1 = time.clock()
47+
t1 = time.perf_counter()
4848
d1 = self.call("com.math.slowsquare", 3)
4949
d1.addCallback(got, t1, "Slow Square")
5050

51-
t2 = time.clock()
51+
t2 = time.perf_counter()
5252
d2 = self.call("com.math.square", 3)
5353
d2.addCallback(got, t2, "Quick Square")
5454

0 commit comments

Comments
 (0)