in reply to Re: Benchmark results | localizing $INPUT_RECORD_SEPARATOR vs spliting contents of file on $INPUT_RECORD_SEPARATOR
in thread Benchmark results | localizing $INPUT_RECORD_SEPARATOR vs spliting contents of file on $INPUT_RECORD_SEPARATOR

-100 is too long
#!/usr/bin/perl ## spin-up hard-disk, init cache ;) Split(); IRS_while(); IRS_map();
use strict; use warnings; use Benchmark qw(cmpthese); my $count = -3; cmpthese($count, { 'Split' => \&Split, 'IRS_while' => \&IRS_while, 'IRS_map' => \&IRS_map, }); sub Split { local $/; my $document; open(FILE, 'removed.xml') or die "Error [$!]\n"; while (<FILE>) { $document .= $_ } my @lines = split('\|',$document); return @lines; } sub IRS_while { local $/ = '|'; my @lines; open(FILE, 'removed.xml') or die "Error [$!]\n"; while (<FILE>) { chomp; push @lines, $_; } return @lines; } sub IRS_map { local $/ = '|'; open(FILE, 'removed.xml') or die "Error [$!]\n"; my @lines = map {chomp; $_} (<FILE>); return @lines; } __END__ Rate IRS_map Split IRS_while IRS_map 7682/s -- -17% -19% Split 9284/s 21% -- -3% IRS_while 9529/s 24% 3% --

irate/tyerate

Rate IRS_map Split IRS_while IRS_map 7682/s -- 0.83 0.81 Split 9284/s 1.21 -- 0.97 IRS_while 9529/s 1.24 1.03 --

And from memory

my $removed = \ scalar read_file('removed.xml'); use File::Slurp; Rate IRS_map IRS_while Split IRS_map 16544/s -- -36% -49% IRS_while 25775/s 56% -- -21% Split 32686/s 98% 27% --

irate/tyerate

Rate IRS_map IRS_while Split IRS_map 16544/s -- 0.64 0.51 IRS_while 25775/s 1.56 -- 0.79 Split 32686/s 1.98 1.27 --
  • Comment on Re^2: Benchmark results | localizing $INPUT_RECORD_SEPARATOR vs spliting contents of file on $INPUT_RECORD_SEPARATOR
  • Select or Download Code

Replies are listed 'Best First'.
Re^3: Benchmark results | localizing $INPUT_RECORD_SEPARATOR vs spliting contents of file on $INPUT_RECORD_SEPARATOR
by MidLifeXis (Monsignor) on Nov 06, 2012 at 14:32 UTC

    Ok, I can agree with that - I don't see how that changes the results. Changed to -3.

    Rate IRS_map Split IRS_while IRS_map 9659/s -- -26% -28% Split 13017/s 35% -- -3% IRS_while 13379/s 39% 3% --

    Considering that a lot of time is in I/O (open and readline), I wonder if the differences between our results are due more to I/O characteristics on our systems than to the algorithm itself.

    --MidLifeXis