Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
Well, yet again I've posted as the AM by mistake, and cannot edit my node:( So, one correction, everywhere I wrote String::IO, that should of course be IO::String.

Now, here's the benchmarks...

results:
Benchmark: timing 10000 iterations of fifo, perlio, string...
      fifo:  8 wallclock secs ( 7.52 usr +  0.00 sys =  7.52 CPU) @ 1329.79/s (n=10000)
    perlio:  1 wallclock secs ( 0.73 usr +  0.00 sys =  0.73 CPU) @ 13698.63/s (n=10000)
    string: 15 wallclock secs (14.82 usr +  0.01 sys = 14.83 CPU) @ 674.31/s (n=10000)
          Rate string   fifo perlio
string   674/s     --   -49%   -95%
fifo    1330/s    97%     --   -90%
perlio 13699/s  1932%   930%     --
the code:
fifo.pm ------- package fifo; # note: this was just a work in progress, now abandoned # and never to be finished, so it's still somewhat crude. use base 'Tie::Handle'; use Symbol (); sub new { my $class = shift; my $self = bless Symbol::gensym(), ref($class) || $class; tie *$self, $self; $self->open(@_); $self; } sub open { my $self = shift; return $self->new(@_) unless ref($self); *$self->{contents} = []; return $self; } sub TIEHANDLE { return $_[0] if ref($_[0]); my $self = bless Symbol::gensym(), $_[0]; $self->open(@_); return $self; } sub PRINT { my $self = shift; push( @{*$self->{contents}}, split( /^/om, join( '', (pop @{*$self->{contents}} || '', @_) ) ) ); } sub PRINTF { my $self = shift; my $fmt = shift; $self->PRINT(sprintf($fmt, @_)); } sub READLINE { return $_[0]->readlines() if wantarray; return shift(@{*{$_[0]}->{contents}}); } sub readlines { my $contents = *{$_[0]}->{contents}; *{$_[0]}->{contents} = []; return @$contents; } sub EOF { return not (scalar @{*{$_[0]}->{contents}}); } 1; benchmark.pl ------------ #!/usr/bin/perl use fifo; use IO::String; my $fh1 = fifo->new(); my $fh2 = IO::String->new(); my $fh3; my $buf = ''; open($fh3, "+<", \$buf); sub foo { for (1..10) { print $fh1 "xxxx\n"; } while (<$fh1>) { # print; } } sub bar { for (1..10) { print $fh2 "xxxx\n"; } $fh2->pos(0); while (<$fh2>) { # print; } $fh2->pos(0); } sub baz { for (1..10) { print $fh3 "xxxx\n"; } seek($fh3, 0, 0); while (<$fh3>) { # print; } seek($fh3, 0, 0); } use Benchmark qw(cmpthese); cmpthese ( 10000, { fifo => \&foo, string => \&bar, perlio => \&baz, } );
-- O thievish Night, Why should'st thou, but for some felonious end, In thy dark lantern thus close up the stars? --Milton

In reply to Re: Re: perl 5.8.0 perlio by Felonious
in thread perl 5.8.0 perlio by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others chilling in the Monastery: (6)
    As of 2014-09-16 05:14 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My favorite cookbook is:










      Results (156 votes), past polls