Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make it 13x faster by making the code unreadable #4

Merged
merged 1 commit into from Jan 10, 2017

Conversation

AlexDaniel
Copy link
Contributor

@AlexDaniel AlexDaniel commented Jan 10, 2017

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.

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.
@MasterDuke17 MasterDuke17 merged commit 630001c into MasterDuke17:master Jan 10, 2017
@MasterDuke17
Copy link
Owner

MasterDuke17 commented Jan 10, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants