in reply to Mysterious slow down with large data set
I can't see what is causing the slowdown, but I can see one obvious thing that would speed it up a lot. You keep re-sorting the keys to %kernel every time when they do not change. Instead of:
foreach $w1 ( sort( keys %kernel ) ){ $totalsim = $maxsim = 0; @topX = (); $at2 = 0; foreach $w2 ( sort( keys %kernel ) ) { ...
Using:
my @sortedKeys = sort( keys %kernel ); foreach $w1 ( @sortedKeys ){ $totalsim = $maxsim = 0; @topX = (); $at2 = 0; foreach $w2 ( @sortedKeys ) {
may speed things up to the point that the slowdown becomes insignificant.
Also, using a sort to track top N is probably slower than a simple linear insertion and truncate if necessary.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Mysterious slow down with large data set
by jsmagnuson (Acolyte) on Feb 26, 2012 at 23:44 UTC | |
by BrowserUk (Patriarch) on Feb 27, 2012 at 00:22 UTC |