3 回答
TA贡献1951条经验 获得超3个赞
整个过程有两件事负责 -
中央处理器
IO 设备
最初,当您将行从一个文件复制到另一个文件时,该过程不涉及 IO 设备(因为您没有打印任何行)。因此,CPU没有等待时间。因此,该过程在更短的时间内完成。
当您引入 println 语句时,对于 CPU 从第一个文件读取的每一行,它必须将该行发送到 IO 设备进行打印。将线路发送到 IO 设备后,CPU 必须等待它完成作业。IO 设备完成打印后,CPU 将继续该过程并将该行粘贴到第二个文件中。此过程将继续,直到第一个文件中的所有行都复制到第二个文件。
因此,对于文件中的每一行,CPU必须等待一定的时间。这是处理时间增加的第一个原因。其次,IO 打印会创建文件的另一个副本。因此,现在您正在创建 2 个副本而不是一个副本。
46,000,000 行?
Let's take the time taken by each operation in the process is 1 microsecond.Initially -
Time took by CPU to copy a line = 1 microsecond
Time took by CPU to paste a line = 1 microsecond
Total time for copying 46,000,000 lines = 46,000,000 microsecond = 46 sec
Total time for pasting 46,000,000 lines = 46,000,000 microsecond = 46 sec
Total time of the entire process = 92 sec.
普印本介绍
Time took by CPU to copy a line = 1 microsecond
Time took by IO to paste a line = 1 microsecond
Time took by CPU to paste a line = 1 microsecond
Waiting time of CPU for every line = 1 microsecond
Total time taken by CPU for copying 46,000,000 lines = 46,000,000 microsecond = 46 sec
Total time taken by IO for copying 46,000,000 lines = 46,000,000 microsecond = 46 sec
Waiting time of CPU = 46,000,000 microsecond = 46 sec
Total time by CPU for pasting 46,000,000 lines = 46,000,000 microsecond = 46 sec
Total time of the entire process = 184 sec.
TA贡献1807条经验 获得超9个赞
“调试”的额外成本非常依赖于平台。println
如果将 您路由到控制台,则可能会因与控制台相关的额外处理而减慢速度。在Windows上默认控制台非常慢,在Linux上是如此之多。PrintStream
此外,如果您正在使用/,您将配置为在每次添加额外开销后冲洗。System.outSystem.errPrintStreamprintln
3小时处理2.5 GiB的磁盘是非常慢的。因此,要么你的代码是复杂的,额外的调试行对整体性能的影响很小,要么你是在Windows上写入默认控制台(在以后的情况下,调试是一个巨大的问题)。println
添加回答
举报