Performance issue? .0002 seconds per sub call? is your input file multi-GB? (assumes $str is coming from a file or DB, which might suggest "performance issue" lies elsewhere).

After adding strict and warnings and dealing with missing variable declarations, on a not-particularly-speedy w32 machine (results similar on Ubuntu):

Extract begins with the input line mycompany----engineer=====itdept--- +--33 1234965298.64138 1234965298.64149 1234965298.64153 1234965298.64158

Update Further thoughts:

#!/usr/bin/perl use strict; use warnings; # use Data::Dumper; use Time::HiRes qw(time); my $Name = "MyName"; my ($Age, %Details); my @source = ('acompany----engineer=====itdept-----33', 'bcompany----butcher=====killingfloor-----34', 'acompany----baker=====oven-----35', 'acompany----candlestickmaker=====tallow-----36', 'acompany----monk=====monastery-----37', ); my $Pattern = "([a-z]+)\-+([a-z]+)\=+([a-z]+)\-+([0-9]+)"; my $start_time = time; for my $str(@source) { Extract($str, $Name, $Pattern); } my $end_time = time; print "back in main elapsed time for a 5-element \@source was: ", $end +_time - $start_time, "\n"; sub Extract { my @subarr = @_; my ($Line,$Name,$Pattern) = @subarr; my (@Arr,$CallId); # print "Extract begins with the input line $Line\n"; # print time,"\n"; @Arr = ($Line =~ m/$Pattern/g); # print time,"\n"; $Age = $Arr[$#Arr]; # print time,"\n"; $Details{$Age}{$Name} = \@Arr if defined($Age); #print time,"\n"; }

Timings: first, with print at line 38 enabled:

C:\ww>perl 744750.pl Extract begins with the input line acompany----engineer=====itdept---- +-33 Extract begins with the input line bcompany----butcher=====killingfloo +r-----34 Extract begins with the input line acompany----baker=====oven-----35 Extract begins with the input line acompany----candlestickmaker=====ta +llow-----36 Extract begins with the input line acompany----monk=====monastery----- +37 back in main elapsed time for a 5-element @source was: 0.0008189678192 +13867

whereas, with line 38 commented out (ie, as shown):

C:\ww>perl 744750.pl back in main elapsed time for a 5-element @source was: 0.0001859664916 +99219

The difference, 0.000633001327514648 (roughly 3x the total elapsed time_when_omitting_the_prints in sub Extract) is attributable to the mis-use of print for profiling. See moritz's above & ELISHEVA's below.


In reply to Re: Performance issue by ww
in thread Performance issue by balakrishnan

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.