Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Make it 13x faster by making the code unreadable
Also, potentially up to 39x faster using the recommendation below.
Every single change in this commit actually had a positive impact on
the performance. It is sad that one has to use nqp for everything to
get things working reasonably fast.
By all means *do not use .min method* in your user code if you want to
get every last drop of performance. At this point everything you do
outside of Sift4 module will have a much bigger impact on the
performance.
For example, this is insanely slow:
say @a.min({ sift4($_, $str, 5) });
And this is twice faster:
my $ans = ‘default value’;
my $ans-min = 6;
for @A {
my $dist = sift4($_, $str, 5, 5);
if $dist < $ans-min {
$ans = $_;
$ans-min = $dist;
}
}
One would think that in the code above 「sift4($_, $str, 5, 5)」 can be
changed to 「sift4($_, $str, 5, $ans-min)」, but no, for some reason it
does not work. Whether it is an issue in this implementation or in the
algorithm itself I don't know. Should be investigated I think.
Anyway, to make it easier for the users I think this module should
provide a function for processing an array (so that users are less
likely to screw it up).
Random testing suggests that these changes do not affect
functionality.- Loading branch information
1 parent
a079c5d
commit 524f98c
Showing
1 changed file
with
84 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters