in reply to Reading from file in threaded code is slow
I am not surprised to see this. If your program is fundamentally “reading from a file,” then it is by definition an I/O-bound task. Adding threads will never help that situation, because, at the end of the day, you have a stream of disk-read requests coming in and a stream of disk-write requests going out, all to the same device.
By adding threads to the mix, you make matters considerably worse because now the pattern of read-requests is scattered all over the platter. Seek time, which is by far the longest component of disk-related delays, is now thrust into front-and-center ... unnecessarily.
The best strategy is to open the file for sequential reading, and read the file sequentially. Do the same with your output file. Now, the operating system’s natural file-buffering heuristics take over. The operating system will “read ahead” and “lazy write.” (As long as you inform the OS that this is what you are doing, that is all you need to do.)