I have a simple text file of ~ 150 MB in size. My code will read every line, and if it matches certain regular expressions, it is written to the output file. But right now, it will take a long time to repeat all lines of the file (several minutes), doing it like
File.open(filename).each do |line|
I know this is a loop over the lines of a file, which takes some time, because even if I do nothing with the data in "# some some stuff", it still takes a lot of time.
I know that some unix programs can parse large files like this almost instantly (like grep), so I wonder why Ruby (MRI 1.9) takes so long to read a file, and is there a way to make it faster?
Davis dimitriov
source share