Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

It turns out that choroba's regex method performs the best for larger data sets and the index method for small sets.

#!/usr/bin/perl use Benchmark qw ( :hireswallclock cmpthese timethese ); use strict; use warnings; # medium data set our $records = "Key\n" . join ( "\n", 1..200000 ); # small data set # our $records = 'Key # 1 # 2 # 3 # 4 # 5'; sub choroba { local $records = $records; $records =~ s/^ # beginning of the string .* # whatever except newline \n # newline //x; #print $records, "\nchoroba\n"; } sub si_lence { local $records = $records; $records = substr($records, 4); #print $records, "\nsi_lence\n"; } sub space_monk { local $records = $records; my @lines = split /^/, $records; shift @lines; # remove first line #print @lines; #print "\nspace_monk\n"; } my $results = timethese( -5, { 'choroba' => 'choroba', 'si_lence' => 'si_lence', 'space_monk' => 'space_monk', } ); cmpthese($results); __END__ **** Results with small data set Benchmark: running choroba, si_lence, space_monk for at least 5 CPU se +conds... choroba: 6.08126 wallclock secs ( 6.09 usr + 0.00 sys = 6.09 CPU) + @ 958995.90/s (n=5843162) si_lence: 6.28688 wallclock secs ( 6.28 usr + 0.00 sys = 6.28 CPU) + @ 1221333.07/s (n=7671193) space_monk: 5.64815 wallclock secs ( 5.64 usr + 0.00 sys = 5.64 CPU) + @ 324712.99/s (n=1831706) Rate space_monk choroba si_lence space_monk 324713/s -- -66% -73% choroba 958996/s 195% -- -21% si_lence 1221333/s 276% 27% -- **** Results with medium data set Benchmark: running choroba, si_lence, space_monk for at least 5 CPU se +conds... choroba: 5.05257 wallclock secs ( 2.20 usr + 2.83 sys = 5.03 CPU) + @ 1639.44/s (n=8248) si_lence: 5.87241 wallclock secs ( 3.84 usr + 2.02 sys = 5.86 CPU) + @ 862.29/s (n=5053) space_monk: 5.16132 wallclock secs ( 5.03 usr + 0.09 sys = 5.12 CPU) + @ 3.51/s (n=18) Rate space_monk si_lence choroba space_monk 3.51/s -- -100% -100% si_lence 862/s 24442% -- -47% choroba 1639/s 46560% 90% --

In reply to Re: Alternative method (aka TIMTOWTDI) by Lotus1
in thread Removing line from a string 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
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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 perusing the Monastery: (8)
    As of 2015-07-04 20:17 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









      Results (60 votes), past polls