Документация для time.perf_counter()
указывает, что это для всей системы
время. perf_counter () → float
Возвращает значение (в долях секунды) счетчика производительности, то есть часов с наибольшим доступным разрешением для измерения короткой длительности.Он включает время, прошедшее во время сна, и является общесистемным.Контрольная точка возвращаемого значения не определена, поэтому допустима только разница между результатами последовательных вызовов.
Неправильно ли я интерпретировал для всей системы , чтобы включить согласованностьмежду процессами?
Как показано ниже, он выглядит согласованным в Linux, но не в Windows.Кроме того, поведение Windows с Python 3.6 значительно отличается от 3.7.
Буду признателен, если кто-нибудь сможет указать документацию или отчеты об ошибках, описывающие это поведение.
Контрольный пример
import concurrent.futures
import time
def worker():
return time.perf_counter()
if __name__ == '__main__':
pool = concurrent.futures.ProcessPoolExecutor()
futures = []
for i in range(3):
print('Submitting worker {:d} at time.perf_counter() == {:.3f}'.format(i, time.perf_counter()))
futures.append(pool.submit(worker))
time.sleep(1)
for i, f in enumerate(futures):
print('Worker {:d} started at time.perf_counter() == {:.3f}'.format(i, f.result()))
Результаты в Windows 7
C:\...>Python36\python.exe -VV
Python 3.6.8 (tags/v3.6.8:3c6b436a57, Dec 24 2018, 00:16:47) [MSC v.1916 64 bit (AMD64)]
C:\...>Python36\python.exe perf_counter_across_processes.py
Submitting worker 0 at time.perf_counter() == 0.000
Submitting worker 1 at time.perf_counter() == 1.169
Submitting worker 2 at time.perf_counter() == 2.170
Worker 0 started at time.perf_counter() == 0.000
Worker 1 started at time.perf_counter() == 0.533
Worker 2 started at time.perf_counter() == 0.000
C:\...>Python37\python.exe -VV
Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05) [MSC v.1916 64 bit (AMD64)]
C:\...>Python37\python.exe perf_counter_across_processes.py
Submitting worker 0 at time.perf_counter() == 0.376
Submitting worker 1 at time.perf_counter() == 1.527
Submitting worker 2 at time.perf_counter() == 2.529
Worker 0 started at time.perf_counter() == 0.380
Worker 1 started at time.perf_counter() == 0.956
Worker 2 started at time.perf_counter() == 1.963
Для краткости я пропустил дополнительные результаты в Windows, но такое же поведение наблюдалось в Windows 8.1.Кроме того, Python 3.6.7 вел себя так же, как 3.6.8, а Python 3.7.1 вел себя так же, как 3.7.3.
Результаты на Ubuntu 18.04.1 LTS
$ python3 -VV
Python 3.6.7 (default, Oct 22 2018, 11:32:17)
[GCC 8.2.0]
$ python3 perf_counter_across_processes.py
Submitting worker 0 at time.perf_counter() == 2075.896
Submitting worker 1 at time.perf_counter() == 2076.900
Submitting worker 2 at time.perf_counter() == 2077.903
Worker 0 started at time.perf_counter() == 2075.900
Worker 1 started at time.perf_counter() == 2076.902
Worker 2 started at time.perf_counter() == 2077.905
$ python3.7 -VV
Python 3.7.1 (default, Oct 22 2018, 11:21:55)
[GCC 8.2.0]
$ python3.7 perf_counter_across_processes.py
Submitting worker 0 at time.perf_counter() == 1692.514
Submitting worker 1 at time.perf_counter() == 1693.518
Submitting worker 2 at time.perf_counter() == 1694.520
Worker 0 started at time.perf_counter() == 1692.517
Worker 1 started at time.perf_counter() == 1693.519
Worker 2 started at time.perf_counter() == 1694.522