Hi Monks,
I'm having a problem with the attached script. When calling the function two times in a row, the 2nd time is by far slower.
The memory usage stays roughly the same, and it does not seem to be an issue of paging either. I wonder if it has to do with some fragmentation?
Is my data structure "too complicated"??
I use it on an XP OS with 2G RAM. Perl 5.8.8 Build 819
#!/usr/bin/perl -w use strict; use warnings; CheckAllPairs(); CheckAllPairs(); sub CheckAllPairs{ my $abs_time_res=50; my $max_peak_time=2050; my $subj_num; my $region; my $region1; my $region2; my $time; my $peaks; my @act_list1; my @act_list2; my $i; my $j; my $key; my $delta; my %map; my $start_A; my $end_A; my $start_B; my $end_B; my @region_list = (1..38); my @main_subjects_list = (1..38); $start_A = (times)[0]; foreach $region (@region_list) { foreach $subj_num (@main_subjects_list){ for $time (0..$max_peak_time){ if(rand(1000)<3){ push(@{$peaks->{$region}{$subj +_num}}, $time); } } } } $end_A = (times)[0]; printf "Section A took %.4f CPU seconds\n", $end_A - $start_A; $start_B = (times)[0]; foreach $region1 (@region_list) { foreach $region2 (@region_list) { if($region2<$region1){ next; } $key=$region1 . ':' . $region2; foreach $subj_num (@main_subjects_list){ if(!exists($peaks->{$region1}{$subj_nu +m}) || !exists($peaks->{$region2}{$subj_num})){ next; } @act_list1=@{$peaks->{$region1}{$subj_ +num}}; @act_list2=@{$peaks->{$region2}{$subj_ +num}}; foreach $i (@act_list1){ foreach $j (@act_list2){ $time=int($i/$abs_time +_res); $delta=int(($j-$i)/$ab +s_time_res)+int($max_peak_time/$abs_time_res); $map{$key}{$subj_num}[ +$time][$delta]=1; } } } } } $end_B = (times)[0]; printf "Section B took %.4f CPU seconds\n", $end_B - $start_B; return; }

In reply to Garbage collection problem?? by tcarmeli

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.