Your IRS_while(), does not return the same information as the other two subroutines. Push returns the size of the array after update. Assignment returns the assigned value. Is it possible that you are getting bogus results due to that?

#!/usr/bin/perl use strict; use warnings; use Benchmark qw(cmpthese); my $count = -100; cmpthese($count, { 'Split' => sub { my $document; open(FILE, 'removed.xml') or die "Error [$!]\n"; while (<FILE>) { $document .= $_ } my @lines = split('\|',$document); return @lines; }, 'IRS_while' => sub { local $/ = '|'; my @lines; open(FILE, 'removed.xml') or die "Error [$!]\n"; while (<FILE>) { chomp; push @lines, $_; } return @lines; }, 'IRS_map' => sub { local $/ = '|'; open(FILE, 'removed.xml') or die "Error [$!]\n"; my @lines = map {chomp; $_} (<FILE>); return @lines; }, });

Results:

Rate IRS_map Split IRS_while IRS_map 9804/s -- -24% -27% Split 12876/s 31% -- -4% IRS_while 13399/s 37% 4% --
and
This is perl 5, version 12, subversion 3 (v5.12.3) built for MSWin32-x +86-multi-thread

Benchmark newbie, so I am certain that I will be corrected if I have also misapplied the tool :-)

Update: To tie into a comment by 2teez, my versions of this seem to be spending a large amount of time in open (32% of total time) and readline (18% of total time) -- a whopping 50% of the total time, with those two items being the top two runners when sorted by exclusive time under Devel::NYTProf.

--MidLifeXis


In reply to Re: Benchmark results | localizing $INPUT_RECORD_SEPARATOR vs spliting contents of file on $INPUT_RECORD_SEPARATOR by MidLifeXis
in thread Benchmark results | localizing $INPUT_RECORD_SEPARATOR vs spliting contents of file on $INPUT_RECORD_SEPARATOR by ashish.kvarma

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, 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.