-
January 16th, 2008, 03:52 AM
#1
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
-
January 16th, 2008, 04:03 AM
#2
Re: How to accelerate std::wofstream
Try turning off sync_with_stdio. Might have significant impact.
More computing sins are committed in the name of efficiency (without necessarily achieving it) than for any other single reason - including blind stupidity. --W.A.Wulf
Premature optimization is the root of all evil --Donald E. Knuth
Please read Information on posting before posting, especially the info on using [code] tags.
-
January 16th, 2008, 04:49 AM
#3
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.
-
January 16th, 2008, 05:05 AM
#4
Re: How to accelerate std::wofstream
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!!
-
January 16th, 2008, 09:20 AM
#5
Re: How to accelerate std::wofstream
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
-
January 16th, 2008, 10:46 AM
#6
Re: How to accelerate std::wofstream
Not sure but try concatenating the string first and write in one go
If there is no love sun won't shine
-
January 16th, 2008, 10:52 AM
#7
Re: How to accelerate std::wofstream
Originally Posted by Paul McKenzie
Are you timing a release build or a debug build?
Regards,
Paul McKenzie
Release
-
January 16th, 2008, 11:13 AM
#8
Re: How to accelerate std::wofstream
-
January 16th, 2008, 12:07 PM
#9
Re: How to accelerate std::wofstream
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'.
-
January 17th, 2008, 07:20 AM
#10
Re: How to accelerate std::wofstream
and how does NtWriteFile not do what u want but faster?
-
January 17th, 2008, 09:19 AM
#11
Re: How to accelerate std::wofstream
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|