From mboxrd@z Thu Jan 1 00:00:00 1970 To: 9fans@9fans.net Date: Thu, 7 Apr 2011 08:45:32 +0000 From: comeau@panix.com (Greg Comeau) Message-ID: References: , <20110406163229.6A159B84A@mail.bitblocks.com> Subject: Re: [9fans] Making read(1) an rc(1) builtin? Topicbox-Message-UUID: cc93e3b4-ead6-11e9-9d60-3106f5b1d025 In article <20110406163229.6A159B84A@mail.bitblocks.com>, Bakul Shah wrote: >On Tue, 05 Apr 2011 15:53:43 MDT andrey mirtchovski wrote: >> so, an optimized /sys/src/cmd/read.c that doesn't read char-by-char >> should give us an improvement, right? right: >> 9grid% newaread >> 1.52u 22.56s 15.66r newaread >> >> and that's just for the silly "test" string. the improvement would be >> bigger for longer strings. > >read(1) is allowed to read one line and no more. Given a read >of > 1 char, a console device will return a line at most but >other devices can return more than one line, thereby >preventing the next guy from reading it. read(1) has to read >one char at a time. > >With a builtin read you don't pay the cost of a fork/exec per >char. And it would be less clunky -- instead of "foo=`{read}" >you can say "read foo". It is not like rc going to get fat by >adding read; it already has to read! It depends upon what you're doing whether it is worth it or not though (not saying you said that, just adding to the conversation). CCsh, my Bourne shell compiler, does make some of the things mentioned in this discussion just become "non-issues" (whatever that means) since they are builtin (and I don't have any numbers handy), however, I'll wager many using it for that purpose are delving into what I'll call false and/or premature opimizations. So, not that it won't make the script faster, but whether in the long run it's a practical compromise. Last comment is that read is a built-in in many UNIX shells, so of course this is not an exact comparison, but still in the end need to get to the practical compromise issue being worthy or not. I won't answer that in the case above though :) -- Greg Comeau / 4.3.10.1 with C++0xisms now in beta! Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90. Comeau C/C++ with Dinkumware's Libraries... Have you tried it?