psutil icon indicating copy to clipboard operation
psutil copied to clipboard

[Linux] [performance] sensors_temperatures(), cpu_freq() are slow

Open nschloe opened this issue 2 years ago • 0 comments

Summary

  • OS: Ubuntu 22.04
  • Type: performance

Description

When profiling tiptop, I noticed that sensors_temperatures() is fairly slow. Compare with cpu_freq:

%timeit psutil.sensors_temperatures()
154 ms ± 31.9 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)
%timeit psutil.cpu_freq()
425 µs ± 7.72 µs per loop (mean ± std. dev. of 7 runs, 1,000 loops each)

Other methods are faster:

%timeit psutil.cpu_count()
4.22 µs ± 23 ns per loop (mean ± std. dev. of 7 runs, 100,000 loops each)
%timeit psutil.cpu_times()
21.9 µs ± 740 ns per loop (mean ± std. dev. of 7 runs, 10,000 loops each)
%timeit psutil.cpu_percent()
27.6 µs ± 109 ns per loop (mean ± std. dev. of 7 runs, 10,000 loops each)

nschloe avatar Mar 07 '22 15:03 nschloe