in reply to Re^10: compare two text file line by line, how to optimise
in thread compare two text file line by line, how to optimise
Looks like your code had 2 loops, each counting to +6 million
foreach my $che (@b){ @aa=split(/\s/,$che); foreach my $kh (@a){ @bb=split(/\s/,$kh); for ($l=0;$l<=$#bb;$l++){ for ($m=0;$m<=$#aa;$m++){ ## this code executes 6 million x 6 million times if(($bb[$l] eq $aa[$m]) ){ .. } } } }
But within the 6 million words, there are only few thousand different ones so your loops were checking the same word thousand of times more than required. By holding the unique words from file1 in a hash you don't have to loop through 6 million words every time to find a match with a word from file2
poj
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^12: compare two text file line by line, how to optimise
by thespirit (Novice) on Feb 29, 2016 at 22:45 UTC | |
by poj (Abbot) on Mar 01, 2016 at 08:23 UTC | |
by thespirit (Novice) on Mar 01, 2016 at 12:59 UTC | |
by poj (Abbot) on Mar 01, 2016 at 13:14 UTC | |
by thespirit (Novice) on Mar 01, 2016 at 16:36 UTC | |
|