回答編集履歴

2

コード修正

2019/01/11 02:54

投稿

YouheiSakurai
YouheiSakurai

スコア6149

test CHANGED
@@ -10,15 +10,15 @@
10
10
 
11
11
  wait_sec = 10
12
12
 
13
- print("%d秒待ちます", wait_sec)
13
+ print("%d秒待ちます" % wait_sec)
14
14
 
15
- now = perf_counter()
15
+ until = perf_counter() + wait_sec
16
16
 
17
- while perf_counter() - now < wait_sec:
17
+ while perf_counter() < until:
18
18
 
19
19
  pass
20
20
 
21
- print("%d秒待ちました", wait_sec)
21
+ print("%d秒待ちました" % wait_sec)
22
22
 
23
23
  ```
24
24
 

1

time.perf_counter_ns

2019/01/11 02:54

投稿

YouheiSakurai
YouheiSakurai

スコア6149

test CHANGED
@@ -25,3 +25,11 @@
25
25
 
26
26
 
27
27
  あとCPUの省電力関係の機能は精度に影響が出るので必ず停止で。
28
+
29
+
30
+
31
+ # 追記
32
+
33
+
34
+
35
+ Python 3.7以降限定ですが[time.perf_counter_ns](https://docs.python.org/ja/3/library/time.html#time.perf_counter_ns)というナノ秒精度の時間計測も場合によっては使っても良いかもしれません。