How to speed up subroutine?

From: nospam (no_at_spam.com)
Date: 08/27/04


Date: Thu, 26 Aug 2004 18:42:24 -0400

The sub below uses the Tie::File module to perform a string
substitution using strings in the hash %strings. The hash
would contain IP addresses, an old and new address,
corresponding to the key/value pairs. The idea is
to replace IP addresses. Anyway, it worked well when
there were about 10 elements in the array, but when
there are ~ 100, the code runs unacceptably slow.
I've tried deferring writing, but that didn't help much.
Anything else I can do to speed up this code, and still
continue using Tie::File?

-Thanks

sub DoReplace {

  $matchflag = 0;

  #Skip things that we don't want to process, namely binaries and dirs.
  #Do a "perldoc -f -f" to view test switches.
  return unless -T;

  my $obj = tie(@array, 'Tie::File', $_) || die "$!\n";

  (tied @array)->defer;

  for (@array) {

    while ((my $key, my $value) = each %strings) {

      if (s/$key/$value/){
        print "Processing==> $File::Find::name\n" unless $matchflag == 1;
        $matchflag = 1;
      }

  (tied @array)->flush;

    }

  }

   untie @array;

}



Relevant Pages

  • The certification password of Internet Explorer 7 and operation of auto complete
    ... About the certification password of Internet Explorer and operation ... By remembering the strings that are input in the following text ... In this registry, there are values whose name is a string of 42 bytes ... We cannot guess the original strings from the hash value, ...
    (Bugtraq)
  • Re: Maximum String size in Java?
    ... > for long strings, so on average, SFH bakes it in the performance ... >> distribution over the hash table size. ... > you need to be concerned about Unicode strings. ... construct a hash function that does appreciably better than the one ...
    (comp.programming)
  • Re: sort unique
    ... given that a hash table is not ... IMO if the vendor's algorithm does something "obvious", ... function to eliminate keys that hash to the same bucket per some ... strings of random lengths, and two strings are ...
    (comp.lang.lisp)
  • Re: Maximum String size in Java?
    ... The hash function will *NOT* have the minimal collision ... > for long strings, so on average, SFH bakes it in the performance ...
    (comp.programming)
  • Re: Performance of hash_set vs. Java
    ... > I would like to convert the vector to store pointers to strings, ... >> reading code and hash table, so we can't really help there. ... and involve many object copies an memory allocations. ... This is the C++ input code I would start with. ...
    (comp.lang.cpp)