估计读取文件的进度
我的应用程序需要显示进度,但是由于性能原因,读取文件两次是第一次计算总数的选项。总数的合理估计是多少?我应该根据文件大小进行估计吗?
my application needs to display progress, however reading the file twice is where the first pass counts the total is not an option due to performance reason. What's a reasonable estimate for the total? should I estimate based on file size?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,基于文件大小。如果您知道总大小和处理的字节数,则可以估计剩余时间。也就是说,如果该处理是某种线性处理。
如果不是,并且文件的某些部分需要更长的时间来读取和处理,则很难做出好的估计。在这种情况下,最好显示一些等待光标,或者(如果需要很长时间)让用户玩一个小游戏来消磨时间。 :)
就像你说的,运行一个进程一次,只是为了能够在显示进度条的同时再次运行它,这绝对不是一个好主意。但你不会是第一个...
Yes, base it on file size. If you know the total size and the amount of bytes processed, you can make an estimate of the remaining time. That is, if this processing is some lineair process.
If it isn't and some portions of the file take much much longer to read and process, it is hard to make a good estimate. In that case, it is better to show some waiting cursor, or (if it takes long) let the user play a little game to kill the time. :)
Like you said, it is never a good idea to run a process once, just to be able to run it again while showing a progress bar. But you wouldn't be the first...