How to accelerate std::wofstream
I have the following code that performs writing into std::wofstream (with conversion into UTF-8):
std::wofstream stream;
stream.open(L"D:\\MyFile.txt", std::ios_base::app | std::ios_base::out);
std::locale utf8locale = <Get UTF-8 locale>;
stream.imbue(utf8locale);
int i;
for (i = 0; i < 700000; ++i)
{
stream.write(L"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", 150);
}
stream.close();
This works too slowly — on computer P-4 3GHz the code (output file is 10 Mb) takes 4.1 sec.
Is it possible to accelerate it?
I have tried to large buffer for the stream (stream.rdbuf()->pubsetbuf(...)) — size of 200 Kb. But this gave no acceleration.
The compiler is MS Visual Studio 2005; Windows XP
Re: How to accelerate std::wofstream
Try turning off sync_with_stdio. Might have significant impact.
Re: How to accelerate std::wofstream
>for (i = 0; i < 700000; ++i)
Sorry, misprint - in fact, there is '70000' in the program, not '700000" (extra zero). So the output file is, really, about 10 Mb. The time is, as I said, 4.1 sec.
Re: How to accelerate std::wofstream
Quote:
Originally Posted by treuss
Try turning off sync_with_stdio. Might have significant impact.
I have tried - no effect.
BTW, when I tried to use std::ofstream instead of std::wofstream - the time was 200 ms! 20 times faster!!
Re: How to accelerate std::wofstream
Quote:
Originally Posted by KellyLynch
I have tried - no effect.
BTW, when I tried to use std::ofstream instead of std::wofstream - the time was 200 ms! 20 times faster!!
Are you timing a release build or a debug build?
Regards,
Paul McKenzie
Re: How to accelerate std::wofstream
Not sure but try concatenating the string first and write in one go
Re: How to accelerate std::wofstream
Quote:
Originally Posted by Paul McKenzie
Are you timing a release build or a debug build?
Regards,
Paul McKenzie
Release
Re: How to accelerate std::wofstream
Re: How to accelerate std::wofstream
Quote:
Originally Posted by Mitsukai
NtWriteFile? I do not think this is what I need. I need to somehow imrpove performance of std::wofstream; not just 'write blocks of bytes into a file'.
Re: How to accelerate std::wofstream
and how does NtWriteFile not do what u want but faster?
Re: How to accelerate std::wofstream
Quote:
Originally Posted by Mitsukai
and how does NtWriteFile not do what u want but faster?
NtWriteFile is writing buffer of bytes into file, right? And I need streamed output - using std::wfostream or some other stream. More exactly, I need WCHAR-based stream - because of my output file is Unicode UTF-8.