I am writing a parser in OCaml and first I need a function to read the object file. I wrote the following function to read the contents of the target file and convert it to string output:
let read_all_lines filename : string = let contents = In_channel.with_open_bin filename In_channel.input_all in contents
When I use this function to read large files, it takes a long time. For example, a file with more than 20,000 lines of code would take 20 seconds to read. Is there any way to optimize it?