9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: comeau@panix.com (Greg Comeau)
To: 9fans@9fans.net
Subject: Re: [9fans] Making read(1) an rc(1) builtin?
Date: Thu,  7 Apr 2011 08:45:32 +0000	[thread overview]
Message-ID: <inilo8$26f$1@panix3.panix.com> (raw)
In-Reply-To: <20110406163229.6A159B84A@mail.bitblocks.com>

In article <20110406163229.6A159B84A@mail.bitblocks.com>,
Bakul Shah <bakul@bitblocks.com> wrote:
>On Tue, 05 Apr 2011 15:53:43 MDT andrey mirtchovski <mirtchovski@gmail.com>  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?



  parent reply	other threads:[~2011-04-07  8:45 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-03 22:30 smiley at zenzebra.mv.com
2011-04-03 23:22 ` pmarin
2011-04-03 23:41 ` Tristan Plumb
2011-04-04  2:02   ` Ethan Grammatikidis
2011-04-04  2:53   ` erik quanstrom
2011-04-04  7:54     ` Tristan Plumb
2011-04-04  9:26     ` roger peppe
2011-04-04 21:35       ` smiley
2011-04-04 21:46         ` Anthony Sorace
2011-04-04 22:03           ` erik quanstrom
2011-04-05  8:57           ` Balwinder S Dheeman
2011-04-04 22:00         ` Oleg Finkelshteyn
2011-04-04 22:33         ` erik quanstrom
2011-04-04 23:01         ` Lyndon Nerenberg
2011-04-05  8:58         ` yy
2011-04-05 19:54           ` Ethan Grammatikidis
2011-04-05 19:56             ` erik quanstrom
2011-04-05 20:54               ` Ethan Grammatikidis
2011-04-05 21:53                 ` andrey mirtchovski
2011-04-06 16:32                   ` Bakul Shah
2011-04-06 16:43                     ` roger peppe
2011-04-06 18:15                       ` erik quanstrom
2011-04-06 18:37                         ` Yaroslav
2011-04-07  8:45                           ` Greg Comeau
2011-04-06 18:18                     ` erik quanstrom
2011-04-07  8:45                     ` Greg Comeau [this message]
2011-04-05  9:10         ` roger peppe
2011-04-05 15:47           ` ron minnich
2011-04-05 15:52             ` Jacob Todd
2011-04-05 15:57               ` erik quanstrom
2011-04-05 16:04               ` Rudolf Sykora
2011-04-05 17:17                 ` ron minnich
2011-04-05 17:49             ` smiley
2011-04-05 18:01               ` erik quanstrom
2011-04-05 19:50               ` Yaroslav
2011-04-06 15:27                 ` smiley
2011-04-06 15:32                   ` Jacob Todd
2011-04-07  1:26                     ` [9fans] Busy mouse WAS: " smiley
2011-04-07 11:49                       ` erik quanstrom
2011-04-07 19:59                         ` smiley
2011-04-07 20:19                           ` erik quanstrom
2011-04-09 12:26                             ` smiley
2011-04-09 12:33                               ` erik quanstrom
2011-04-05 16:28         ` [9fans] " dexen deVries
2011-04-05 17:05         ` Bakul Shah
2011-04-03 23:51 ` Lyndon Nerenberg (VE6BBM/VE7TFX)
2011-04-04  3:01 ` erik quanstrom

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='inilo8$26f$1@panix3.panix.com' \
    --to=comeau@panix.com \
    --cc=9fans@9fans.net \
    /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 NNTP newsgroup(s).