stdio performance in tango, stdlib, and perl

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


Walter Bright wrote:
> Andrei Alexandrescu (See Website For Email) wrote:
>> I've ran a couple of simple tests comparing Perl, D's stdlib (the 
>> coming release), and Tango.
> 
> Can you add a C++ <iostream> to the mix? I think that would be a very 
> useful additional data point.

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

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


Andrei



More information about the Digitalmars-d mailing list