in reply to perl quicker than bash?
Just taking a guess at what you are doing, I created a file of 1500 random IP-like addresses
$ perl -E ' say join q{.}, map { int rand 256 } 1 .. 4 for 1 .. 1500;' > spw1112250.dat $
I then put a script together to read the file and construct a hash keyed on the first three octets then look up another octet to see if it occurred in the data file. I timed the process in the script which took milliseconds rather than seconds on a fairly old laptop.
use strict; use warnings; use 5.014; use Time::HiRes qw{ gettimeofday tv_interval }; my $startTV = [ gettimeofday() ]; my $inFile = q{spw1112250.dat}; open my $inFH, q{<}, $inFile or die qq{open: < $inFile: $!\n}; my @lines = <$inFH>; close $inFH or die qq{close: < $inFile: $!\n}; s{\.\d+$}{} for @lines; my %lookupIPs; @lookupIPs{ @lines } = ( 1 ) x @lines; my $lookFor = q{17.23.213}; say qq{$lookFor }, $lookupIPs{ $lookFor } ? q{} : q{not }, qq{found in $inFile}; say qq{Process took @{ [ tv_interval( $startTV, [ gettimeofday() ] ) ] + } seconds};
The output.
17.23.213 not found in spw1112250.dat Process took 0.002678 seconds
Of course, your integer comparison may be more complex than this simple lookup. Perhaps you could show us exactly what your comparison does.
Cheers,
JohnGG
|
|---|