stdcxx-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Martin Sebor <se...@roguewave.com>
Subject Re: simple iostream benchmark
Date Wed, 16 May 2007 04:31:39 GMT
mark.g.brown wrote:
> Hi,
> 
> I wrote the attached simple benchmark program to compare iostreams
> and C stdio. Running it with -10000000 and 10000000 on the command
> line on Linux 2.6.9 (GNU libc 2.5) I get the numbers below for each
> of the implementations I tried when using /dev/null and /tmp/file
> as the sink:
> 
>                  /dev/null      /tmp/file
>                 CLK:USR:SYS    CLK:USR:SYS
> 
> stdio           28s:27s:0.0s   32s:28s:1.8s
> g++ 4.1.1       42s:42s:0.0s   44s:42s:2.0s
> stdcxx trunk    40s:41s:0.0s   49s:41s:5.8s
> STLport 5.1.3   27s:27s:0.0s   30s:27s:2.3s

Thanks for posting this! The numbers I got the last time I pit stdcxx
against libstdc++ and STLport were quite a bit different and much more
in favor of stdcxx. I recall having tested integer and floating point
I/O separately with the integer part looking real good while the rest
wasn't as great. So maybe that's what accounts for the difference
here? It would be interesting to see it broken down. Either way it's
clear we have some work to do...

Martin

> 
> The CLK, USR, and SYS abbreviations stand for wall clock, user time,
> and system time. In all cases I used -D_REENTRANT, -O2 and -pthread
> to compile and link.
> 
> -- Mark
> 
> 
> ------------------------------------------------------------------------
> 
> #include <cstdio>
> #include <cstdlib>
> #include <ios>
> #include <iostream>
> #include <fstream>
> 
> const char* strings[] = {
>     "zero", "one", "two", "three", "four", "five", "six", "seven", "eight",
>     "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen",
>     "sixteen", "seventeen", "eighteen", "nineteen", "twenty"
> };
> 
> int test (int from, int to, const char *fname, bool stdio = false)
> {
>     if (stdio) {
> 
>         std::cout << "Running stdio loop: " << from << ", " <<
to << '\n';
> 
>         std::FILE* f = std::fopen (fname, "w");
>         if (!f)
>             return 1;
> 
>         for (int i = from; i < to; ++i) {
>             short  s = i;
> 
>             const char* str =
>                 strings [i % (sizeof strings / sizeof *strings)];
> 
>             if (0 > std::fprintf (f, "\"%s\" %hd %x\n", str, s, i)) {
>                 std::cerr << "Error writing " << fname << " at " <<
i << '\n';
>                 return 1;
>             }
>         }
> 
>         return 0;
>     }
> 
>     std::cout << "Running iostream loop: " << from << ", " <<
to << '\n';
> 
>     std::ofstream strm (fname);
> 
>     for (int i = from; i < to; ++i) {
>         short s = i;
> 
>         const char* str =
>             strings [i % (sizeof strings / sizeof *strings)];
> 
>         if (!(strm << '"' << str << "\" "
>               << s << ' '
>               << i << ' '
>               << '\n')) {
>             std::cerr << "Error writing " << fname << " at " <<
i << '\n';
>             return 1;
>         }
>     }
> 
>     return 0;
> }
> 
> int main (int argc, char *argv [])
> {
>     int from = 1 < argc ? std::atoi (argv [1]) : 0;
>     int to = 2 < argc ? std::atoi (argv [2]) : 0;
>     const char* fname = 3 < argc ? argv [3] : "/dev/null";
>     bool stdio = 4 < argc;
> 
>     test (from, to, fname, stdio);
> }


Mime
View raw message