Marija Silajev wrote:
> 
> Hi,

Hello,

> this is the output of profiler showing the bottle neck of a program.
> 
>      count wall tm  cpu time line
>     14788 0.000000 0.000000    82:sub check_positive{
>     14788 0.072474 0.260000    83:    local $a = 0;
                                        ^^^^^^^^^^^^
Why use $a instead of a lexical variable?


>     14788 0.072475 0.270000    84:    my ($addr) = @_;
>     14788 0.630970 0.710000    85:    tie %hash,
> "GDBM_File",$whois_record, &GDBM_WRCREAT, 0644;
> 
>  11666247 547.4904 679.2700    86:    foreach my $cidr (keys %hash){
>  11666247 595.2517 736.3500    87: my $block = new Net::Netmask($cidr);
>  11666247 581.9811 698.1900    88: if (($block -> match($addr)) != 0){
>     14788 28.59408 28.25000    89:     return $cidr, $hash{$cidr};
>                                         }
> 
> so the idea is the following:
> I previously form %hash written in GDBM_File. This hash has network
> address (for example 170.60.0.0/16) as a key and as value -the network
> name. In this subroutine I compare ip address against this network
> address to see if ip address match network (with the help of
> Net::Netmask module). If it matches I give back the key and value to
> main program.
> 
> There is 14788 ip addresses for which I am checking. And in the hash
> there is around 1519  keys .
> 
> Total time in this subroutine at the end is around 1900 sec...around
> half an hour, what is a lot!
> 
> How can I more efficiently iterate over GDBM file or any idea how to
> make it working faster. Will 'while' loop make it faster?

Instead of opening the file every time the subroutine is called, you
should open it once in the main program.  You could store the hash in
memory and then write it back out to the file if any changes were made.



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to