On Tue, 05 Apr 2011 15:53:43 MDT andrey mirtchovski <mirtchov...@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!