Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 23 Apr 2006 22:32:26 +0200
From:      Benjamin Lutz <benlutz@datacomm.ch>
To:        freebsd-chat@freebsd.org
Cc:        Dan Strick <strick@covad.net>, dan@mist.nodomain
Subject:   Re: Why is not more FreeBSD software written in C++?
Message-ID:  <200604232232.32653.benlutz@datacomm.ch>
In-Reply-To: <200604231525.k3NFP64X003155@mist.nodomain>
References:  <200604231525.k3NFP64X003155@mist.nodomain>

next in thread | previous in thread | raw e-mail | index | archive | help
--nextPart1686217.LuTWpC3WUS
Content-Type: text/plain;
  charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Hello Dan,

On Sunday 23 April 2006 17:25, Dan Strick wrote:
> My results show something quite different.  Even though the buffer
> size used by Benjamin's write() test (61 bytes) is much larger than
> the one I used (only 24 bytes), the write() test to /dev/null still
> takes about 4 times longer than the putchar() test.  As one might
> expect, the write() test spends most of its time in the kernel doing
> all those write() system calls.  The putchar() test (i.e. stdio)
> is probably using a 1K byte buffer.

Your results are intriguing. I ran the tests again on a FreeBSD-6 machine (=
A=20
Sempron 3000+), and I see the same thing, test_putchar runs faster and with=
=20
much lower cpu load than test_write.

I'm not sure what to make of this. I would have said that the reason that=20
write() is faster is because there's much fewer kernel calls necessary. I'm=
=20
beginning to think though that FreeBSD's write(2) implementation is not as=
=20
good as it could be. My Linux Mac Mini using a notebook HD actually runs=20
test_write 10% faster than the FreeBSD Sempron 3000+ using proper SATA disk=
s.

Or maybe Linux just cheats by doing some smart delaying/caching.

Thinking about it some more, I think you're right with your assumption that=
=20
test_putchar is faster because stdio does some internal buffering. I ran=20
ktrace on test_putchar (the version with 500'000 lines), and it calls write=
()=20
4562 times on said FreeBSD system, each time with 0x1000 as last argument, =
ie=20
it uses 4KB buffers. To confirm that buffering to be the reason, I increase=
d=20
the size of each line from 61 bytes to 16001 bytes, at which point the=20
write() version showed a clear performance advantage on FreeBSD as well.

I had not thought about this possibility when I made my original statement.=
=20
Given that, it makes sense that putchar is quite fast.

It still puzzles me though why the Mini (it's only a 1.25GHz G4!) beats the=
=20
Sempron though.

> I stand by my suggestion that using putchar() might not be slower.
> On my system it was much faster.

Ok, I accept that then. If we think of a case where buffering must not happ=
en,=20
and thus a putchar() must be followed by a fflush(), would you agree that=20
just using write() is faster?

Cheers
Benjamin

--nextPart1686217.LuTWpC3WUS
Content-Type: application/pgp-signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (GNU/Linux)

iD8DBQBES+RggShs4qbRdeQRAuKiAKCMMKlSqyVQ4iPWjl57tC1P09Pd0gCfZnHv
ZD3ubC1zpcJp1RevrflvVXE=
=nQTd
-----END PGP SIGNATURE-----

--nextPart1686217.LuTWpC3WUS--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200604232232.32653.benlutz>