stdio performance in tango, stdlib, and perl
Sean Kelly
sean at f4.ca
Thu Mar 22 08:49:10 PDT 2007
torhu wrote:
> James Dennett wrote:
> <snip>
>> Try the way IOStreams would be used if you didn't want
>> it to go slowly:
>>
>> #include <string>
>> #include <iostream>
>>
>> int main() {
>> std::ios_base::sync_with_stdio(false);
>> std::cin.tie(NULL);
>> std::string s;
>> while (std::getline(std::cin, s)) {
>> std::cout << s << '\n';
>> }
>> }
> <snip>
>
>
> I did some tests with a 58 MB file, containing one million lines. I'm
> on winxp. I ran each test a few times, timing them with a stopwatch. I
> threw in a naive C version, and a std.cstream version, just out of
> curiousity.
>
> It seems that using cin.tie(NULL) doesn't matter with msvc 7.1, but with
> mingw it does. Basically, Tango wins hands down on my system. Whether
> the Tango version flushes after each line or not, doesn't seem to matter
> much on Windows.
...
> ---
> // Tango
> import tango.io.Console;
>
> void main() {
> char[] line;
>
> while (Cin.nextLine(line)) {
> //Cout(line).newline;
> Cout(line)("\n");
> }
> }
> ---
Oh good. I was hoping someone would test Tango without flushing every
line :-) Basically, Tango's 'newline' method is equivalent to C++'s
'endl' mutator function. It should not be used for every carriage
return in normal output for performance-critical applications. Rather,
it should be used as the trailing newline after writing a block of data
that should be displayed immediately ('flush' is another option if no
newline is desired).
Sean
More information about the Digitalmars-d
mailing list