0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

処理の残り時間予測と表示

0
Posted at
MATLABのfor文で、1回の処理時間を計測し、平均処理時間から残り時間と完了予定時刻を推測する

N = 10000;  % 処理回数

totalTime = 0;

for i = 1:N
    tic;

    % ---- ここに処理を記述 ----
    :
    :
    :
    % --------------------------

    t = toc;
    totalTime = totalTime + t;

    % 進捗表示(100回ごと)
    if mod(i, 100) == 0 || i == N
        avgTime = totalTime / i;
        remainTime = avgTime * (N - i);
        finishTime = datetime('now') + seconds(remainTime);

        fprintf(['進捗: %d/%d (%.1f%%), ' ...
                 '経過: %s, 残り: %s, 完了予定: %s\n'], ...
            i, N, i/N*100, ...
            char(duration(0, 0, totalTime, 'Format', 'hh:mm:ss')), ...
            char(duration(0, 0, remainTime, 'Format', 'hh:mm:ss')), ...
            char(finishTime, 'yyyy-MM-dd HH:mm:ss'));
    end
end
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?