饮歌长啸
整个过程有两件事负责 -中央处理器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 microsecondTime took by CPU to paste a line = 1 microsecondTotal time for copying 46,000,000 lines = 46,000,000 microsecond = 46 secTotal time for pasting 46,000,000 lines = 46,000,000 microsecond = 46 secTotal time of the entire process = 92 sec.普印本介绍Time took by CPU to copy a line = 1 microsecondTime took by IO to paste a line = 1 microsecondTime took by CPU to paste a line = 1 microsecondWaiting time of CPU for every line = 1 microsecondTotal time taken by CPU for copying 46,000,000 lines = 46,000,000 microsecond = 46 secTotal time taken by IO for copying 46,000,000 lines = 46,000,000 microsecond = 46 secWaiting time of CPU = 46,000,000 microsecond = 46 secTotal time by CPU for pasting 46,000,000 lines = 46,000,000 microsecond = 46 secTotal time of the entire process = 184 sec.