I had written a program that writes to a comma delineated file and it takes forever to finish running. Below is a simplified version of the program that compiles. I was wondering if anyone could tell me if there was a way to make this program more efficient by changing the code so that it finished running sooner? Also I was thinking of buying a new laptop. If I did and wanted this program to run as fast as possible what hardware should I get? For example should I get a ssd hardrive, or as much RAM as possible, or the fastest processor? What component would be the most important?
Since you're writing 66 MB of data to a file, I'd tend to say disk performance is the largest factor.
You can also reduce the number of memory reallocations caused by vector by reserving a specified capacity before actual usage.
This is probably closer to how I'd have written it:
> I/O operations are expensive
> First step, get rid of the vectors
'foo' is expensive, so modify 'bar'
> directly write your strings into the file
unless you mean myfile.write( big_chunk, sizeof(big_chunk) ); which has a different meaning, I don't see how you may access an string more "directly"
@Cubbi: I would swap the first and second step.
If the code is good enough there is no need to modify it