stdio performance in tango, stdlib, and perl

Walter Bright newshound at digitalmars.com
Wed Mar 21 15:48:57 PDT 2007


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.



More information about the Digitalmars-d mailing list