in reply to Using threads to process multiple files

Actually threads won't be of any use in your case. You will win time when a thread that doesn't use the CPU (ie: it is waiting for the GPU or the hard drive to answer (which is really slow)) makes the unused CPU time available to a heavier computational part, instead of just waiting until the action is done before going to the next step. But here, you don't do much except reading from two files from two files. Which means that often, when a thread releases the CPU for the other because it is waiting for the hard drive, the other thread won't be able to do anything (the hard drive won't be ready yet), and will have to wait even before it could try to read the content of the file.

Besides, I suppose that if you are trying to make your program faster, it means your files are pretty heavy, which may mean several hard drive accesses even with buffering, and by alternating between the two threads, you will keep jumping from one place on the HD to another, instead of reading a whole file and jumping to the other. Even with fragmentation, reading a whole file at once, and then a second is probably less expansive timewise than going from one file to the other.

  • Comment on Re: Using threads to process multiple files