This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
libstdc++/9876: filebuf::sputc more than 10% slower than putc
- From: peturr02 at ru dot is
- To: gcc-gnats at gcc dot gnu dot org
- Date: 27 Feb 2003 10:34:44 -0000
- Subject: libstdc++/9876: filebuf::sputc more than 10% slower than putc
- Reply-to: peturr02 at ru dot is
>Number: 9876
>Category: libstdc++
>Synopsis: filebuf::sputc more than 10% slower than putc
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Thu Feb 27 10:36:01 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator: peturr02 at ru dot is
>Release: gcc-3.2.1
>Organization:
>Environment:
Red Hat Linux 8.0
>Description:
filebuf::sputc is more than 10% slower than putc with these tests:
time ./stdio
10.97user 1.60system 0:12.79elapsed 98%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (23major+9minor)pagefaults 0swaps
time ./iostreams
12.56user 1.89system 0:14.66elapsed 98%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (80major+15minor)pagefaults 0swaps
****** speed.hh ******
#ifndef SPEED_HH_INCLUDED
#define SPEED_HH_INCLUDED
const int iterations = 100000000;
#endif
****** stdio.cc ******
#include <cstdio>
#include "speed.hh"
int main()
{
using namespace std;
FILE* file = fopen("tmp", "w+");
for (int i = 0; i < iterations; ++i)
{
putc(i % 100, file);
}
fclose(file);
return 0;
}
****** iostreams.cc ******
#include <fstream>
#include "speed.hh"
int main()
{
using namespace std;
filebuf buf;
buf.open("tmp", ios_base::out | ios_base::in | ios_base::trunc);
for (int i = 0; i < iterations; ++i)
{
buf.sputc(i % 100);
}
buf.close();
return 0;
}
>How-To-Repeat:
>Fix:
This speed difference disappears if streambuf::sputc is inlined and all the cruft deleted so it looks like:
int_type sputc(char_type c)
{
if (pptr() < epptr())
{
*pptr() = c;
pbump(1);
return traits_type::to_int_type(c);
}
else
return overflow(traits_type::to_int_type(c));
}
>Release-Note:
>Audit-Trail:
>Unformatted: