Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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":



  • 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.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2024-04-26 08:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found