Re: Perl Quiz of the Week #23

Kurt Starsinic <[email protected]>
Newsgroups gmane.comp.lang.perl.qotw.discuss
Message-ID <[email protected]>
On Fri, 03 Sep 2004 08:24:53 -0400, colin.rafferty-/PgpppG8B+R7qynMiXIxWgC/[email protected]
<colin.rafferty-/PgpppG8B+R7qynMiXIxWgC/[email protected]> wrote:
> Xavier Noria wrote:
> > On Sep 3, 2004, at 14:00, colin.rafferty-/PgpppG8B+R7qynMiXIxWgC/[email protected] wrote:
> 
> >> paias746 $ time ~/misc/qotw/parens 12 | head
> >> (((((((((((())))))))))))
> >> ((((((((((()()))))))))))
> >> (((((((((()(()))))))))))
> >> ((((((((()((()))))))))))
> >> (((((((()(((()))))))))))
> >> ((((((()((((()))))))))))
> >> (((((()(((((()))))))))))
> >> ((((()((((((()))))))))))
> >> (((()(((((((()))))))))))
> >> ((()((((((((()))))))))))
> >>
> >> real 0m0.05s
> >> user 0m0.01s
> >> sys  0m0.01s
> 
> > My goodness:
> 
> > % time perl balanced_gen.pl 12
> > perl balanced_gen.pl 12  4.38s user 0.03s system 83% cpu 5.255 total
> 
> You are looking at the wrong number.  In the one you're showing, I'm
> doing `head', so it's cut off after 10 results.  You really should be
> looking at the results of the full run to see that we're in the same
> ballpark.

    I assert that most of the time for any non-brain-damaged
implementation will be spent in the tty driver.  In my implementation
(which just so happens to produce its output in lexicographic order):

    % time parens 12
    [ output not shown ]
    real    0m18.137s
    user    0m5.940s
    sys     0m3.912s
    % time parens 12 | head
    [ output not shown ]
    real    0m0.079s
    user    0m0.050s
    sys     0m0.004s
    % time parens 12 | tail
    [ output not shown ]
    real    0m4.780s
    user    0m4.510s
    sys     0m0.114s
    % time parens 12 > /dev/null
    real    0m4.541s
    user    0m4.460s
    sys     0m0.012s

    The "tail" version has to generate all the output, it just doesn't
have to display most of it to the s*l*o*w tty.  Interestingly, the
"/dev/null" version isn't that much faster, which reinfoces the idea
that the slowness isn't in the I/O subsystem per se, but rather in the
tty driver specifically.

    - Kurt
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.