This is the sort of code where I would expect to be faster in C. Lots of numerical comparisons, and not much else. However, there are a couple of things that jump out at me. One is your
mvsrt() routine. I think you could remove that entirely by changing this line:
my $tv = mvsrt($cv, $oper, $amt);
to this:
my $tv = ( ($cv <=> $amt) == ($oper - 1) );
(Well, that changes the actual operation each value of $oper performs, but you get the idea.)
Also, you have lots of C-style for loops which could be rewritten to use foreach. For example, change this:
my $absMax = 0;
for(my $i = $params[1] - 5; $i < $params[1]; $i++){
if($rddt[$i] > $absMax){
$absMax = $rddt[$i];
}
}
$returnValue = $rddt[$params[1]] - $absMax;
to this:
my $absMax = 0;
# loop over array slice
foreach my $rddt_value (@rddt[($params[1] - 5) .. $params[1]])
+{
if($rddt_value > $absMax){
$absMax = $rddt_value;
}
}
$returnValue = $rddt[$params[1]] - $absMax;
Foreach loops do tend to run quite a bit faster, and you have many of these.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.