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.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.