From owner-freebsd-chat@FreeBSD.ORG Sun Apr 23 20:32:41 2006 Return-Path: X-Original-To: freebsd-chat@freebsd.org Delivered-To: freebsd-chat@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id E83CB16A400 for ; Sun, 23 Apr 2006 20:32:40 +0000 (UTC) (envelope-from benlutz@datacomm.ch) Received: from maxlor.mine.nu (c-213-160-32-54.customer.ggaweb.ch [213.160.32.54]) by mx1.FreeBSD.org (Postfix) with ESMTP id DFC7F43D58 for ; Sun, 23 Apr 2006 20:32:39 +0000 (GMT) (envelope-from benlutz@datacomm.ch) Received: from localhost (unknown [127.0.0.1]) by maxlor.mine.nu (Postfix) with ESMTP id 790122E0A7; Sun, 23 Apr 2006 22:32:35 +0200 (CEST) X-Virus-Scanned: amavisd-new at atlantis.intranet Received: from maxlor.mine.nu ([127.0.0.1]) by localhost (atlantis.intranet [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id J7L3wE3lmCDF; Sun, 23 Apr 2006 22:32:35 +0200 (CEST) Received: from mini.intranet (mini.intranet [10.0.0.17]) by maxlor.mine.nu (Postfix) with ESMTP id 40DAF2E0A6; Sun, 23 Apr 2006 22:32:35 +0200 (CEST) From: Benjamin Lutz To: freebsd-chat@freebsd.org Date: Sun, 23 Apr 2006 22:32:26 +0200 User-Agent: KMail/1.8.3 References: <200604231525.k3NFP64X003155@mist.nodomain> In-Reply-To: <200604231525.k3NFP64X003155@mist.nodomain> X-Face: $Ov27?7*N,h60fIEfNJdb!m,@#4T/d; 1hw|W0zvsHM(a$Yn6BYQ0^SEEXvi8>D`|V*F"=?iso-8859-1?q?=5F+R=0A?= 2@Aq>+mNb4`,'[[%z9v0Fa~]AD1}xQO3|>b.z&}l#R-_(P`?@Mz"kS; XC>Eti,i3>%@g?4f,=?iso-8859-1?q?=5Cc7=7CGh=0A?= =?iso-8859-1?q?_wb=26ky=24b2PJ=5E=5C0b83NkLsFKv=7CsmL/cI4UD=25Tu8alAD?= MIME-Version: 1.0 Content-Type: multipart/signed; boundary="nextPart1686217.LuTWpC3WUS"; protocol="application/pgp-signature"; micalg=pgp-sha1 Content-Transfer-Encoding: 7bit Message-Id: <200604232232.32653.benlutz@datacomm.ch> Cc: Dan Strick , dan@mist.nodomain Subject: Re: Why is not more FreeBSD software written in C++? X-BeenThere: freebsd-chat@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Non technical items related to the community List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 23 Apr 2006 20:32:41 -0000 --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--