-
Faster Output to Disk
Right now I have a program that loops, and if given the right conditions writes to disk.
Because of this it write a lot of small files, and currently I am naming the files with std::sprintf and writing to that file with std::ofstream.
Without calling this write to disk function it takes 4 seconds to finish, but with it (written on a ram disk) it takes 24 seconds, 6 times as long!
While this doesn't matter that much in certain situations it runs much longer (2 minutes without writing) and could be much longer.
Would there be any other faster way in order to make multiple small files?
Thanks!
Code:
char filename[100];
std::sprintf(filename, "%05.0lf.txt", numberofFiles);
std::ofstream ofs(filename);
for(int o = 0; o<100; o++)
{
if( outputClean[o][0][0] != '\0')
ofs << "abcde " << outputClean[o][1] << " " << outputClean[o][0][0] << endl;
}
for(int o = 0; o < 100; o++)
{
if(outputClean[o][0][0] != '\0')
{
ofs << "fghij ";
for(int i = 1; i < 10; i++)
{
if(outputClean[o][i][0] != '0')
ofs << outputClean[o][i] << " ";
}
ofs << "\n";
}
}
ofs << "END";
numberofFiles++;
-
If the desired end result is a lot of small files, then the answer is no.
Sure, you could speed up THIS program by say writing one large file, but then you would need to spend time waiting for another program to split the large file up into a number of small files.
If you have no care at all about portability, then use the lowest level platform API calls for doing the same things (open, write, close).
It might buy you some improvement, but chances are it will still be closer to 24 than 4.