I want to get the cpu usage during testing for my ML model (during a call to predict). Here is currently what I am doing. p is the current process:
start = p.cpu_percent(interval=1)
y_hat = clf.predict(X_test)
print(abs(p.cpu_percent(interval=None) - start)) # prints cpu usage (%)
Is this the correct approach or is there a better way to achieve this?