比较 fread 与 read.table 读取 100M 中前 1M 行的速度

Comparing speed of fread vs. read.table for reading the first 1M rows out of 100M

我有一个 14GB data.txt 文件。我通过读取前 1M 行来比较 freadread.table 的速度。看起来 fread 慢得多,尽管它不应该如此。显示百分比计数需要一些时间。

可能是什么原因?我认为它应该超级快...我使用的是 Windows OS 计算机。

fread mmaps 文件。这需要一些时间,并且会映射整个文件。这意味着后续 "read-ins" 会更快。

read.table 不是 mmap 整个文件。它可以逐行读取文件[并在第 1000000 行停止]。

您可以在 mmap mmap() vs. reading blocks

上看到一些背景

来自 fread 的帮助中的示例强调了这种行为