This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: libstdc++/9876: filebuf::sputc more than 10% slower than putc


> Needless to say, you are right, and Nathan is right, about the need to
> improve our streambuf::sputc, but we still do _not_ have real numbers
> to use as a point of reference.
> 
> Are you willing to work on this?

This is stdio vs. unlocked_stdio vs. iostreams:

time ./stdio
1.11user 0.15system 0:01.27elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (22major+8minor)pagefaults 0swaps
time ./stdio_unlocked
0.28user 0.15system 0:00.43elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (22major+8minor)pagefaults 0swaps
time ./iostreams
1.00user 0.19system 0:01.20elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (61major+15minor)pagefaults 0swaps

This is on a Intel Pentium III 500 MHz with 384 MB ram, Red Hat Linux 8.0
with kernel 2.5.44.

This is the code:

========================== speed.hh ============================

#ifndef SPEED_HH_INCLUDED
#define SPEED_HH_INCLUDED

const int iterations = 10000000;

#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;
}

========================== stdio_unlocked.cc ============================

#include <cstdio>
#include "speed.hh"

int main()
{
	using namespace std;

	FILE* file = fopen("tmp", "w+");
	for (int i = 0; i < iterations; ++i)
	{
		putc_unlocked(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::out | ios::in | ios::trunc);
	for (int i = 0; i < iterations; ++i)
	{
		buf.sputc(i % 100);
	}
	buf.close();
	return 0;
}

====================================================================

There are also major differences in fwrite vs. filebuf::sputn when
the buffer is bigger than BUFSIZ (fwrite doesn't copy the buffer when
it is larger than BUFSIZ), as well as in putwc vs. wfilebuf::sputc
(I think that codecvt is causing this slowdown).

Petur


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]