估计可变运行时间的剩余时间

时间:2019-02-17 18:26:29

标签: java time time-estimation

我有一个Java项目,该项目正在废弃大量HTML,我想显示剩余时间的估算值。

我想我可以在每个循环的开始和结束时获取时间(以毫秒为单位),然后减去以获得运行的总时间。然后我计算出我确切地知道我需要经历多少次,因此我可以乘以该次数以获得总的估计时间。

然后,对于剩余的估计时间,我可以保持运行总时间,并从总估计时间中减去。

问题是我的输出似乎是负数...?

CurrentPage ++;                 长时间= System.currentTimeMillis();

            // Calculate Time
            long runtime = timestart - timeend;
            long timetotal = 0;
            timetotal = timetotal + runtime;
            long averagetime = timetotal / CurrentPage;
            long timeestimated = averagetime * totalpages;
            long timeremaining = timeestimated -timetotal;


            String RunTime= String.format("%d min, %d sec", TimeUnit.MILLISECONDS.toMinutes(runtime), TimeUnit.MILLISECONDS.toSeconds(runtime));
            String AverageTime=String.format("%d min, %d sec", TimeUnit.MILLISECONDS.toMinutes(averagetime), TimeUnit.MILLISECONDS.toSeconds(averagetime));
            String TimeEstimated=String.format("%d min, %d sec", TimeUnit.MILLISECONDS.toMinutes(timeestimated), TimeUnit.MILLISECONDS.toSeconds(timeestimated));
            String TimeRemaining=String.format("%d min, %d sec", TimeUnit.MILLISECONDS.toMinutes(timeremaining), TimeUnit.MILLISECONDS.toSeconds(timeremaining));


            System.out.println("Page " + CurrentPage +" completed");
            System.out.println("Current Runtime = " + RunTime);
            System.out.println("Average Runtime = " + AverageTime);
            System.out.println("Estimated time = " + TimeEstimated);
            System.out.println("Estimated time remaining  = " +TimeRemaining);

我的输出看起来像这样:

Page 9 completed
Current Runtime = 0 min, -3 sec
Average Runtime = 0 min, 0 sec
Estimated time = 0 min, -3 sec
Estimated time remaining  = 0 min, 0 sec
Page 10 completed
Current Runtime = 0 min, -3 sec
Average Runtime = 0 min, 0 sec
Estimated time = 0 min, -3 sec
Estimated time remaining  = 0 min, 0 sec
Page 11 completed
Current Runtime = 0 min, -4 sec
Average Runtime = 0 min, 0 sec
Estimated time = 0 min, -3 sec
Estimated time remaining  = 0 min, 0 sec

所以我显然做错了,但无法完全弄清楚这是什么。当我运行10个循环时,“当前运行时间”总计为20秒,而“构建/运行时间”为27秒……所以我很茫然。

0 个答案:

没有答案