home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / perl / 5624 < prev    next >
Encoding:
Text File  |  1992-08-31  |  3.0 KB  |  75 lines

  1. Newsgroups: comp.lang.perl
  2. Path: sparky!uunet!cis.ohio-state.edu!magnus.acs.ohio-state.edu!namra
  3. From: namra@magnus.acs.ohio-state.edu (Nasir K Amra)
  4. Subject: speeding up access and processing of 650,000 record database
  5. Message-ID: <1992Aug31.140632.14392@magnus.acs.ohio-state.edu>
  6. Sender: news@magnus.acs.ohio-state.edu
  7. Nntp-Posting-Host: top.magnus.acs.ohio-state.edu
  8. Organization: The Ohio State University
  9. Date: Mon, 31 Aug 1992 14:06:32 GMT
  10. Lines: 63
  11.  
  12.  
  13.     I currently have a program which takes a game file (consisting
  14. of 60 moves) and then searches a 650,000 record database file (46
  15. megabyte) to count game configurations that are consistent with the
  16. moves at each move. Currently the program takes 3 hours on a single
  17. game file which is much too long.  I've tried to load the whole
  18. database file in an array on a 64 megabyte Sparc II , but Perl gives
  19. me an "Out of Memory!" error message which I find hard to believe. Do
  20. I have to reconfigure Perl in order to exploit the memory available on
  21. the workstation? If so , how? 
  22.     I believe a significant amount of processing time is spent in
  23. comparing each record in the database file with each move in the game
  24. file. Currently I use the pattern matching operator =~ /pattern/ to
  25. test equality between the accumulated move pattern and the record
  26. pattern. Is there a faster way to do this? I've appended the
  27. subroutine which processes the game file below (any help would be much
  28. appreciated): 
  29.  
  30. # the database is structured so that a record consists of an 8
  31. # numeric string that is the configuration and a 64 numeric string
  32. # that is the pattern.
  33. $template="A8 A64";
  34. sub process_datafile {
  35.     local($recnum);
  36.     $recnum = 1;
  37.     open(BB,"<$bb_database") || die "Couldn't open $bb-database";
  38.        while ( (read(BB,$record,$recordsize))) {
  39.            #process record.
  40.        ( $config , $pattern ) = unpack ($template, $record);
  41.        #process moves of datafile
  42.        for ($j = 1; $j <= $game ; $j++ ) {
  43.            #variables for each game
  44.            for ($k = 1; $k <= 32 ; $k++) {
  45.            $gamepattern[$k] = "\\d\\d"; }
  46.            for ($i = 1; $i <= $moves[$j]; $i++  ) {
  47.            #variables for each move
  48.            if ($event{$j,$i} =~ /Shoot Ray/){
  49.                if ($to{$j,$i} < 10) {
  50.                $gamepattern[$from{$j,$i}] = "0" . $to{$j,$i}; }
  51.                else {
  52.                $gamepattern[$from{$j,$i}] = $to{$j,$i} ; }
  53.                $testpattern = join("", @gamepattern) . "\n"; 
  54.                if ($pattern =~ /$testpattern/ ) {
  55.                #yes $testpattern matches $pattern 
  56.                $yes{$j,$i} = $yes{$j,$i} + 1; # of patterns in database
  57.                                                       # consistent with game pattern
  58.                }
  59.                else { # no need to continue to cycle through moves since $pattern is not consistent
  60.                last ; # exits loop through moves for statement.
  61.                }
  62.            }
  63.            }
  64.        }
  65.             $recnum++;
  66.        }
  67.  
  68. }
  69.  
  70. -- 
  71. ---------------------------------------------------------------------
  72. Nasir K. Amra                     amra@med.ohio-state.edu
  73. Laboratory for Knowledge Based Medical Systems
  74. 571 Health Science Library,376 W. 10th , Columbus, Ohio, 43210
  75.