Seq.map is different from Array.map . Since sequences ( IEnumerable<T> ) are not evaluated until they are listed, in F # style code, no computation actually happens until File.WriteAllLines passes through the sequence (not an array) generated with using Seq.map .
In other words, your C # -style version reverses all the lines and stores the reverse lines in the array, and then iterates over the array to write to the file. The F # line version reverses all lines and writes more or less of them directly to the file. This means that C # style code cycles through the entire file three times (reading an array, creating an inverse array, writing an array to a file), while F # style code cycles through the entire file only two times (reading into an array, writing return lines to file).
You will get maximum performance if you use File.ReadLines instead of File.ReadAllLines in combination with Seq.map - but your output file should be different from your input file, since you write output when reading from input.
Joel mueller
source share