in reply to Improving script's speed and performance...
Well, whatever you do, you should start right here. You call this function 300000000 times, and it does a lot of things, . Does it actually increase performance (compared to just using lcss on strings?) I mean, it might, but it allocates hashes and strings, accesses keys and values in hashes, runs the regex engine...sub lcssw { my ($s1, $s2) = @_; my $i; my %codes; my %words; for ($s1, $s2) { $_ = join '', map { $codes{$_} = chr(++$i) if !exists($codes{$_}); $codes{$_} } $_ =~ /\w+/g; } my $lcss = lcss($s1, $s2); $lcss = "" if (!defined $lcss); @words{values %codes} = keys %codes; return join ' ', @words{ $lcss =~ /./sg }; }
Also, while your lcssw could be improved (for example, return '' if not defined $lcss), real optimizations depend on your data. Are there many strings that won't match? You could try to filter them out using some simpler algorithm, and then run the full version on others. How gigantic are your strings? If not too big, you can preprocess them (that is, do most of the work that lcssw does, but just once per array - at least for the smaller array).
The whole thing looks pretty parallelizable, threads or forks could help with using more CPUs to process your arrays.Anyway, without some representative examples of your data it's hard to tell, so how about posting some.
|
|---|