This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: [Patch] Step2: don't use _M_out_lim in filebuf, have filebuf non unified, etc...
On Tue, Jun 24, 2003 at 06:33:33PM +0200, Paolo Carlini wrote:
> >On Tue, Jun 24, 2003 at 12:17:26AM +0200, Paolo Carlini wrote:
> Nathan Myers wrote:
> >Once we get the streambuf inlines shuffled around between
> >std/std_streambuf.h and bits/streambuf.tcc, we'll be ready to run
> >some races. Eat our dust, stdio! :-)
>
> Anyway, *right now*, on my P4, for 9876
>
> 1.990u 0.370s 0:02.37 99.5% 0+0k 0+0io 215pf+0w (stdio unlocked)
> 1.480u 0.380s 0:01.94 95.8% 0+0k 0+0io 216pf+0w (iostream)
I ran another benchmark, attached below, on several compilers
on P3 and Opteron. All builds are -O2.
P3 1.4GHz.
----------
gcc version 2.95.4 20011002 (Debian prerelease)
stdio (unlocked): 2.54u 0.10s 4.60r
streambuf: 21.87u 0.13s 23.24r
gcc version 3.2.2 20021230 (prerelease)
stdio (unlocked): 1.88u 0.07s 2.52r
streambuf: 14.34u 0.06s 14.87r
Mainline gcc version 3.4 20030624 (experimental)
stdio (unlocked): 1.82u 0.13s 3.57r
streambuf: 5.89u 0.05s 7.45r
Mainline w/ inlines
stdio (unlocked): 1.85u 0.10s 2.65r
streambuf: 2.10u 0.09s 2.79r
Opteron 1.4GHz
---------------
gcc 3.2.2
stdio (unlocked): 1.60u 1.14s 2.93r
streambuf: 9.56u 0.98s 12.22r
gcc version 3.4 20030613:
stdio (unlocked): 1.69u 1.02s 4.48r
streambuf: 4.81u 0.65s 6.65r
Mainline gcc version 3.4 20030624 (experimental)
stdio (unlocked): 1.68u 0.28s 2.52r
streambuf: 4.48u 0.40s 5.37r
Mainline w/inlines
stdio (unlocked): 1.64u 0.34s 3.52r
streambuf: 3.08u 0.33s 4.91r
$ time dd if=/dev/zero of=/dev/null bs=8k count=32768
real 0m0.647s
user 0m0.000s
sys 0m0.650s
We still have some room for improvement, perhaps. :-)
Nathan Myers
ncm-nospam@cantrip.org
p.s. This is the test program. It exercises both input and output, and
uses /dev/zero and /dev/null (respectively) to minimize OS effects.
=========
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <sys/times.h>
#include <sys/time.h>
#include <time.h>
#include <unistd.h>
const unsigned long count = 1ul << 28;
int main()
{
const long ticksper = sysconf(_SC_CLK_TCK);
tms before;
times(&before);
timeval tvbefore;
gettimeofday(&tvbefore, 0);
FILE* fpi = fopen("/dev/zero", "r");
FILE* fpo = fopen("/dev/null", "w");
for (unsigned long i = 0; i < count; ++i) {
int c = getc_unlocked(fpi);
if (c != EOF) {
putc_unlocked(c, fpo);
}
}
fclose(fpi);
fclose(fpo);
tms middle;
times(&middle);
timeval tvmiddle;
gettimeofday(&tvmiddle, 0);
std::filebuf in;
in.open("/dev/zero", std::ios::in);
std::filebuf out;
out.open("/dev/null", std::ios::out);
for (unsigned long i = 0; i < count; ++i) {
int c = in.sbumpc();
if (c != EOF) {
out.sputc(c);
}
}
in.close();
out.close();
tms after;
times(&after);
timeval tvafter;
gettimeofday(&tvafter, 0);
printf("stdio (unlocked):\t%.02fu\t%.02fs\t%.02fr\n",
double(middle.tms_utime - before.tms_utime) / ticksper,
double(middle.tms_stime - before.tms_stime) / ticksper,
double(tvmiddle.tv_sec) + .000001 * double(tvmiddle.tv_usec) -
double(tvbefore.tv_sec) + .000001 * double(tvbefore.tv_usec)
);
printf("streambuf: \t%.02fu\t%.02fs\t%.02fr\n",
double(after.tms_utime - middle.tms_utime) / ticksper,
double(after.tms_stime - middle.tms_stime) / ticksper,
double( tvafter.tv_sec) + .000001 * double( tvafter.tv_usec) -
double(tvmiddle.tv_sec) + .000001 * double(tvmiddle.tv_usec)
);
return 0;
}