是否可以在同一执行期间 运行 memory_profiler 和 line_profiler ?
Is it possible to run memory_profiler and line_profiler during the same execution?
我有一个 python 程序,我正在尝试计算它的内存使用量和 运行 时间。当我 运行 使用 kernprof -l -v 的程序时,我只得到 memory_profiler 的输出。它确实说 line_profiler 已将输出写入外部文件,但终端和文件中都没有输出。如果我 运行 程序分别使用 mprof 运行 然后使用 kernprof -l -v 而不是导入内存分析器输出在那里,我可以查看时间结果。是否可以让它们在同一次执行中工作?我的代码:
@profile
def ARIMA_forecast(series, df):
X = series.values
size = int(len(X) * 0.66)
train, test = X[0:size], X[size:len(X)]
history = [x for x in train]
predictions = list()
for t in range(len(test)):
model = ARIMA(history, order=(4, 1, 0))
model_fit = model.fit(disp=0)
output = model_fit.forecast()
yhat = output[0]
predictions.append(yhat)
obs = test[t]
history.append(obs)
print('predicted=%f, expected=%f' % (yhat, obs))
# evaluate forecasts
rmse = sqrt(mean_squared_error(test, predictions))
print('Test RMSE: %.3f' % rmse)
# plot forecasts against actual outcomes
plt.plot(series, label='Training data')
plt.plot(series[size:len(X)].index, predictions, color='blue', label='Predicted Price')
plt.plot(series[size:len(X)].index, test, color='red', label='Actual Price')
plt.legend()
plt.show()
df = pd.read_csv('MSFT.csv', header=0, index_col=0, parse_dates=True)
series = df['Adj Close']
ARIMA_forecast(series, df)
``
据我所知,Scalene 是唯一同时分析 Python 程序的 CPU 执行时间 和 的分析器记忆(以及许多其他事物)。它也比 memory_profiler
快很多。强制免责声明:我是 Scalene 的主要作者。让我知道进展如何!
我有一个 python 程序,我正在尝试计算它的内存使用量和 运行 时间。当我 运行 使用 kernprof -l -v 的程序时,我只得到 memory_profiler 的输出。它确实说 line_profiler 已将输出写入外部文件,但终端和文件中都没有输出。如果我 运行 程序分别使用 mprof 运行 然后使用 kernprof -l -v 而不是导入内存分析器输出在那里,我可以查看时间结果。是否可以让它们在同一次执行中工作?我的代码:
@profile
def ARIMA_forecast(series, df):
X = series.values
size = int(len(X) * 0.66)
train, test = X[0:size], X[size:len(X)]
history = [x for x in train]
predictions = list()
for t in range(len(test)):
model = ARIMA(history, order=(4, 1, 0))
model_fit = model.fit(disp=0)
output = model_fit.forecast()
yhat = output[0]
predictions.append(yhat)
obs = test[t]
history.append(obs)
print('predicted=%f, expected=%f' % (yhat, obs))
# evaluate forecasts
rmse = sqrt(mean_squared_error(test, predictions))
print('Test RMSE: %.3f' % rmse)
# plot forecasts against actual outcomes
plt.plot(series, label='Training data')
plt.plot(series[size:len(X)].index, predictions, color='blue', label='Predicted Price')
plt.plot(series[size:len(X)].index, test, color='red', label='Actual Price')
plt.legend()
plt.show()
df = pd.read_csv('MSFT.csv', header=0, index_col=0, parse_dates=True)
series = df['Adj Close']
ARIMA_forecast(series, df)
``
据我所知,Scalene 是唯一同时分析 Python 程序的 CPU 执行时间 和 的分析器记忆(以及许多其他事物)。它也比 memory_profiler
快很多。强制免责声明:我是 Scalene 的主要作者。让我知道进展如何!