From owner-freebsd-chat@FreeBSD.ORG Mon Apr 24 02:28:07 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 B26B116A400 for ; Mon, 24 Apr 2006 02:28:07 +0000 (UTC) (envelope-from dugger@hotlz.com) Received: from www.hotlz.com (freedom.hotlz.com [209.20.218.52]) by mx1.FreeBSD.org (Postfix) with ESMTP id BDF2643D76 for ; Mon, 24 Apr 2006 02:27:53 +0000 (GMT) (envelope-from dugger@hotlz.com) Received: from [172.27.240.45] (henry.local.hotlz.com [172.27.240.45]) by www.hotlz.com (8.13.3/8.13.3) with ESMTP id k3O2RZ0G051728; Sun, 23 Apr 2006 19:27:36 -0700 (PDT) (envelope-from dugger@hotlz.com) Message-ID: <444C3797.7010909@hotlz.com> Date: Sun, 23 Apr 2006 19:27:35 -0700 From: Don Dugger User-Agent: Thunderbird 1.5.0.2 (Macintosh/20060308) MIME-Version: 1.0 To: freebsd-chat@freebsd.org References: <200604231525.k3NFP64X003155@mist.nodomain> <200604232232.32653.benlutz@datacomm.ch> In-Reply-To: <200604232232.32653.benlutz@datacomm.ch> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: Benjamin Lutz , Dan Strick 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: Mon, 24 Apr 2006 02:28:07 -0000 For fun I run the tests on a SUN box I have here it's an old Sparc 200MHz Running Solaris 8. and I used the gcc 3.4.2 compiler. ---------- time ./test_putchar >/dev/null real 0m0.45s user 0m0.44s sys 0m0.01s time ./test_write >/dev/null real 0m0.66s user 0m0.38s sys 0m0.28s time ./test_iostream >/dev/null real 0m3.28s user 0m3.12s sys 0m0.04s time ./test_string >/dev/null real 0m1.50s user 0m1.48s sys 0m0.02s ---------- Don 8) Benjamin Lutz wrote: > 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 > Sempron 3000+), and I see the same thing, test_putchar runs faster and with > much lower cpu load than test_write. > > I'm not sure what to make of this. I would have said that the reason that > write() is faster is because there's much fewer kernel calls necessary. I'm > beginning to think though that FreeBSD's write(2) implementation is not as > good as it could be. My Linux Mac Mini using a notebook HD actually runs > test_write 10% faster than the FreeBSD Sempron 3000+ using proper SATA disks. > > 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 > test_putchar is faster because stdio does some internal buffering. I ran > ktrace on test_putchar (the version with 500'000 lines), and it calls write() > 4562 times on said FreeBSD system, each time with 0x1000 as last argument, ie > it uses 4KB buffers. To confirm that buffering to be the reason, I increased > the size of each line from 61 bytes to 16001 bytes, at which point the > write() version showed a clear performance advantage on FreeBSD as well. > > I had not thought about this possibility when I made my original statement. > 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 > 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 happen, > and thus a putchar() must be followed by a fflush(), would you agree that > just using write() is faster? > > Cheers > Benjamin >