The Datecalc function in this loop slows my script down greatly. With it, it takes minutes to run and about 15 seconds without. I've tried to avoid using it by just adding 30 or 60 seconds to the $seconds variable but keep getting unusual results. Help? This takes a series of data and puts all the timestamps into 5 minute increments (and adds 3 hours)...
my @data = split(/\,/,$Client{$client}{$cmd}); my $time = $data[0]; for ($i=3; $i<=$#data; $i++) { $seconds = &UnixDate("$time","%s"); if ($cmd eq 'RTT') { $time = &DateCalc("$time","+ 1minute",\$err); $value = sprintf("%0.2f", ($data[$i]/1000)); } else { $time = &DateCalc("$time","+ 30seconds",\$err +); $value = sprintf("%0.2f", (($data[$i]*8)/1000) +); # Convert to bits then / by 1000 for graphing } $seconds = (int($seconds/300))*300; $Counter{$seconds}++; $Tot{$seconds}+=$value; $Max{$seconds}=$value if ($value>$Max{$seconds}); $Min{$seconds}=$value if (($value<$Min{$seconds})or(!$ +Min{$seconds})); }
This is what I was getting when I tried to avoid using Datecalc and instead used the $i variable and multiplied it by the # of seconds to skip... As you can see, it worked for a bit but then started drifting more and more...

04/28/05.07:15:00       0.03    0.03    0.03
04/28/05.07:20:00       0.03    0.03    0.03
04/28/05.07:25:00       0.03    0.03    0.03
04/28/05.07:30:00       0.03    0.03    0.03
04/28/05.07:35:00       0.03    0.03    0.03
04/28/05.07:40:00       0.03    0.03    0.03
04/28/05.07:50:00       0.03    0.03    0.03
04/28/05.08:00:00       0.05    0.05    0.05
04/28/05.08:10:00       0.03    0.03    0.03
04/28/05.08:20:00       0.03    0.03    0.03
04/28/05.08:30:00       0.03    0.03    0.03
04/28/05.08:45:00       0.03    0.03    0.03
04/28/05.09:00:00       0.03    0.03    0.03
04/28/05.09:15:00       0.03    0.03    0.03
04/28/05.09:30:00       0.03    0.03    0.03
04/28/05.09:45:00       0.03    0.03    0.03
04/28/05.10:05:00       0.03    0.03    0.03
04/28/05.10:25:00       0.03    0.03    0.03
04/28/05.10:45:00       0.03    0.03    0.03
.
.
.
This is all necessary because the original data looks like this. Time, interval, # of elements, then results
07:30:04,60,750,32058,41,98,41,41,98,43,41,73,98,18050,467,428,260,363 +,836,258,1499,247,489,1208,469,633,749,439,342,258,706,817,639 ,2174,848,909,557,876,1633,1116,1090,665,1150,817,1592,791,1741,935,67 +5,2370,2039,2121,911,1955,1526,608,656,375,1488,529,376,268,10 82,1858,2036,1282,859,1356,1654,1620,2074,1546,488,2999,1564,1509,811, +1427,2149,611,1548,803,2313,1823,1575,1733,1168,2511,1034,2090 ,1491,2361,2663,2062,1455,957,3549,3097,2443,2680,2262,2152,2176,2645, +3029,2078,1395,1961,801,1955,1395,1465,1030,976,1026,813,932,1 745,450,1172,1457,.....

Janitored by Arunbear - added code tags, to prevent distortion of site layout


In reply to Avoiding Datecalc by Earindil

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.