[Bangalore-pm] Need Help to optimise the code

simran simran at tlims.cc
Mon Jun 15 20:35:11 PDT 2009


Hi Srinivas,

You can also try the benchmark module...
http://perldoc.perl.org/Benchmark.html

simran.

2009/6/16 Kiran Kumar <mkirank at gmail.com>

> you will not be able to compare hashes but you can convert your data to
> strings and it will make it easier , something like this
>
> #!perl
> use strict;
>
> use warnings;
> use Data::Dumper;
>
> my @arr =(
> {
>     'row' => 33,
>     'col' => 1,
>     'value' => 'xx',
> },
>
> {
>     'row' => 30,
>     'col' => 1,
>     'value' => 'zz',
> },
>
> {
>     'row' => 34,
>     'col' => 1,
>     'value' => 'yy',
> },
>
> );
>
> my @arr1 =(
>
> {
>     'row' => 33,
>     'col' => 1,
>     'value' => 'xx',
> },
>
> {
>     'row' => 30,
>     'col' => 1,
>     'value' => 'zz',
> },
>
> {
>     'row' => 35,
>     'col' => 1,
>     'value' => 'yy',
> },
>
> );
>
>
> my @vals =  map {$_->{'row'} > 32 && $_->{'col'} > 0 ?stringify(%$_):()}
> @arr;
> my @vals1 =  map {$_->{'row'} > 32 && $_->{'col'} > 0 ?stringify(%$_):()}
> @arr1;
>
>
> my %hash;
> @hash{@vals} = 1  x @vals;
> my @diff =  grep {not exists$hash{$_}} @vals1;
>
>
> sub stringify {
>      return "@_";
>
> }
>
>
>
>
> 2009/6/15 Srinivas Reddy <SReddy at securities.com>
>
>>  Hi Thnx a lot for your quick help. Sry C is rules out as this willl form
>> a part of perl script and we have ‘C’ Expertise issue as well. I think
>> kumars solution would really help . Let us rewrite it and check the
>> performance.
>>
>>
>>
>> I am still looking at a function which takes 2 arrays and gives me the
>> difference in them , in my case these array contain my xls file ( row , col
>> and value associated with each cell ) .
>>
>>
>>
>> Regards,
>>
>>
>>
>> Srinivas Reddy
>>
>> Asia Technology and Global Projects Manager
>>
>> Skype : sreddyisi
>>
>> Cell : +91 9740076449
>>
>> LandLine : +91 9900524073/74/76./78
>>
>> Fax : +91 8026729764
>>
>> Url : www.securities.com
>>
>> www.thefinancialnet.com
>>
>> elearning.securities.com
>>
>> P Please consider the environment before printing this email
>>   ------------------------------
>>
>> *From:* simrangambhir at gmail.com [mailto:simrangambhir at gmail.com] *On
>> Behalf Of *simran
>> *Sent:* Monday, June 15, 2009 6:17 PM
>> *To:* Srinivas Reddy
>> *Cc:* bangalore-pm at pm.org
>> *Subject:* Re: [Bangalore-pm] Need Help to optimise the code
>>
>>
>>
>> Hi Srinivas,
>>
>> The code is not very complex, and unless you change the structure, it will
>> not optimise too much... better to write it neatly (and with better arg
>> passing... as suggested in the email by Ravish.
>>
>> If you are looking for absolute speed, better to write in in C and plug it
>> in via XS.
>>
>> simran.
>>
>> 2009/6/15 Srinivas Reddy <SReddy at securities.com>
>>
>> Hi ,
>>
>>
>>
>> Please help to optimize the code below.  We basically read 2 xls files
>> into an array @xls2 and @xls1 . For each cell we want to compare ( starting
>> from col 32 ) values in each cell and if they are not equal we need to store
>> it in a different array. This we will then use to bold those particular
>> cells.
>>
>>
>>
>> The loop which does this comparison could be replacement by some in built
>> array difference kind of function. I am new to perl so apologies if I ve
>> used any wrong terminologies here.  Appreciate your help on the same. Please
>> find attached whole code as well for reference
>>
>>
>>
>> sub cell_handler2 {
>>
>>
>>
>>         my $workbook    = $_[0];
>>
>>         my $sheet_index = $_[1];
>>
>>         my $row         = $_[2];
>>
>>         my $col         = $_[3];
>>
>>         my $cell        = $_[4];
>>
>>              # Construct array for Dx code
>>
>>
>>
>>         push @xls2 , {
>>
>>                         'row2' => $row,
>>
>>                         'col2' => $col,
>>
>>                         'value2' => $cell->value(),
>>
>>         };
>>
>>         return @xls2;
>>
>>
>>
>> }
>>
>> #print Dumper(@xls2);
>>
>> # Print the End Time to read second excel file
>>
>> print scalar(localtime) . ": End Reading Excel2 \n";
>>
>>
>>
>> print scalar(localtime) . ": Start Populating Bolding Array \n";
>>
>> # Inefficient way of looping
>>
>> # Please change this as it could boost the performance significantly
>>
>> for(@xls2) {
>>
>>             if($_->{'col2'} > 32 && $_->{'row2'} > '0' ) {
>>
>>                                     $newvalue = $_->{'value2'};
>>
>>                                     $newrow = $_->{'row2'};
>>
>>                                     $newcol = $_->{'col2'};
>>
>>                                     for(@xls1) {
>>
>>                                                 $oldrow = $_->{'row1'};
>>
>>                                                 $oldcol = $_->{'col1'};
>>
>>
>>                                                 if($_->{'col1'} > 32 &&
>> $_->{'row1'} > 0 && $_->{'row1'} eq $newrow && $_->{'col1'} eq $newcol) {
>>
>>
>> $oldvalue = $_->{'value1'};
>>
>>
>> last;
>>
>>                                                 }
>>
>>                                     }
>>
>>                                     if($oldvalue ne $newvalue) {
>>
>>                                                 push @bold_array , {
>>
>>                                                             'row' =>
>> $_->{'row2'},
>>
>>                                                             'col' =>
>> $_->{'col2'},
>>
>>                                                             'value' =>
>> $_->{'value2'},
>>
>>                                                 };
>>
>>                                     }
>>
>>             }
>>
>> }
>>
>>
>>
>>
>>
>> Regards,
>>
>>
>>
>> Srinivas Reddy
>>
>>
>> ______________________________________________________________________
>> This communication contains information which is confidential. It is for
>> the
>> exclusive use of the intended recipient(s). If you are not the intended
>> recipient(s) please note any distribution, copying or use of this
>> communication or the information in it is strictly prohibited. If you have
>> received this communication in error please notify us by e-mail or
>> by telephone (as above) and then delete the e-mail and all attachments and
>> any copies thereof.
>> ______________________________________________________________________
>>
>>
>> _______________________________________________
>> Bangalore-pm mailing list
>> Bangalore-pm at pm.org
>> http://mail.pm.org/mailman/listinfo/bangalore-pm
>>
>>
>>
>> ______________________________________________________________________
>> This communication contains information which is confidential. It is for
>> the
>> exclusive use of the intended recipient(s). If you are not the intended
>> recipient(s) please note any distribution, copying or use of this
>> communication or the information in it is strictly prohibited. If you have
>> received this communication in error please notify us by e-mail or
>> by telephone (as above) and then delete the e-mail and all attachments and
>> any copies thereof.
>> ______________________________________________________________________
>>
>> _______________________________________________
>> Bangalore-pm mailing list
>> Bangalore-pm at pm.org
>> http://mail.pm.org/mailman/listinfo/bangalore-pm
>>
>
>
> _______________________________________________
> Bangalore-pm mailing list
> Bangalore-pm at pm.org
> http://mail.pm.org/mailman/listinfo/bangalore-pm
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/bangalore-pm/attachments/20090616/d1414cd0/attachment-0001.html>


More information about the Bangalore-pm mailing list