On Sat, 22 Mar 2008 23:40:56 +0100, "Bo Persson"
>Yes, obviously the default file buffering is not optimal. Let us "fix"
>that:
>
>char Cache[150000000];
>
>int main()
>{
>
> std::ifstream src("bible.txt");
> std::ofstream dst("output.txt");
>
> dst.rdbuf()->pubsetbuf(Cache, sizeof Cache);
>
> clock_t start=clock();
>
> //etc.
>
For 119 meg file, I got times like
C:\>CopyFile
Time for reading and writing file: 3750 ms
C:\>CopyFile
Time for reading and writing file: 3718 ms
C:\>CopyFile
Time for reading and writing file: 3703 ms
C:\>CopyFile
Time for reading and writing file: 3703 ms
C:\>CopyFile
Time for reading and writing file: 3766 ms
for Java it was
Time for reading and writing files: 2219 ms (java)
Time for reading and writing files: 2156 ms (java)
Time for reading and writing files: 2250 ms (java)
Time for reading and writing files: 2453 ms (java)
The compiler options were C:\>cl /O2 CopyFile.cpp
Why the difference?
I used this
#include
#include
#include
char Cache[150000000];
int main(int argc,char *argv[])
{
std::ifstream src("bible3.txt");
std::ofstream dst("output.txt");
clock_t start=clock();
dst.rdbuf()->pubsetbuf(Cache, sizeof Cache);
dst << src.rdbuf();
clock_t endt=clock();
std::cout <<"Time for reading and writing file: " <<
double(endt-start)/CLOCKS_PER_SEC * 1000 << " ms\n";
return 0;
}
Is that what you meant?