【问题标题】:Is it possible to run memory_profiler and line_profiler during the same execution?是否可以在同一执行期间运行 memory_profiler 和 line_profiler?
【发布时间】:2021-02-14 08:13:10
【问题描述】:

我有一个 python 程序,我正在尝试计算它的内存使用情况和运行时间。当我使用 kernprof -l -v 运行程序时,我只得到 memory_profiler 的输出。它确实说 line_profiler 已将输出写入外部文件,但终端和文件中都没有输出。如果我用 mprof run 单独运行程序,然后用 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)

``

【问题讨论】:

    标签: python memory time profiler


    【解决方案1】:

    据我所知,Scalene 是唯一一个同时针对 CPU 执行时间内存(以及许多其他内容)分析 Python 程序的分析器。它也比memory_profiler很多。强制性免责声明:我是 Scalene 的主要作者。告诉我进展如何!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-19
      • 1970-01-01
      • 2013-01-05
      • 1970-01-01
      • 2013-09-20
      • 2021-07-19
      相关资源
      最近更新 更多