stdio performance in tango, stdlib, and perl

Andrei Alexandrescu (See Website For Email) SeeWebsiteForEmail at erdani.org
Wed Mar 21 15:57:36 PDT 2007


Walter Bright wrote:
> Andrei Alexandrescu (See Website For Email) wrote:
>> Obliged. Darn, I had to wait a *lot* longer.
>>
>> #include <string>
>> #include <iostream>
>>
>> int main() {
>>   std::string s;
>>   while (getline(std::cin, s)) {
>>     std::cout << s << '\n';
>>   }
>> }
>>
>> (C++ makes the same mistake wrt newline.)
>>
>> 35.7s        cppcat
> 
> This is awesomely bad. Although it's possible to get very fast code out 
> of C++, it rarely seems to happen when you write straightforward code.
> 
> 
>> I seem to remember a trick that puts some more wind into iostream's 
>> sails, so I tried that as well:
>>
>> #include <string>
>> #include <iostream>
>> using namespace std;
>>
>> int main() {
>>   cin.sync_with_stdio(false);
>>   cout.sync_with_stdio(false);
>>   string s;
>>   while (getline(std::cin, s)) {
>>     cout << s << '\n';
>>   }
>> }
>>
>> Result:
>>
>> 13.3s        cppcat
> 
> Turning off sync is cheating - D's readln does syncing.

I don't know exactly what sync'ing does in C++, but probably it isn't 
the locking that you are thinking of.

Andrei



More information about the Digitalmars-d mailing list