public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: peturr02@ru.is
To: gcc-gnats@gcc.gnu.org
Subject: libstdc++/9876: filebuf::sputc more than 10% slower than putc
Date: Thu, 27 Feb 2003 10:36:00 -0000	[thread overview]
Message-ID: <20030227103444.15884.qmail@sources.redhat.com> (raw)


>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@ru.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:


             reply	other threads:[~2003-02-27 10:36 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-02-27 10:36 peturr02 [this message]
2003-02-27 20:22 paolo
2003-02-28 16:06 Pétur Runólfsson
2003-02-28 16:46 Paolo Carlini
2003-03-03 11:16 Pétur Runólfsson
2003-03-23 19:46 Pétur Runólfsson
2003-05-16 17:56 Paolo Carlini
2003-05-16 18:06 Benjamin Kosnik

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20030227103444.15884.qmail@sources.redhat.com \
    --to=peturr02@ru.is \
    --cc=gcc-gnats@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).