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

Update PrimePas.dpr #264

Closed
wants to merge 1 commit into from

Conversation

KimMadsen
Copy link

@KimMadsen KimMadsen commented Jul 3, 2021

Performance improved version that nearly doubles performance.

Description

Contributing requirements

  • I read the contribution guidelines in CONTRIBUTING.md.
  • I placed my solution in the correct solution folder.
  • I added a README.md with the right badge(s).
  • I added a Dockerfile that builds and runs my solution.
  • I selected drag-race as the target branch.
  • All code herein is licensed compatible with BSD-3.

Performance improved version that nearly doubles performance.
@KimMadsen
Copy link
Author

Performance improved Delphi code.

@glenkleidon
Copy link

glenkleidon commented Jul 9, 2021

See my pull request #365 - Adding the Inline compiler hint for getbit and clear bit also doubles performance. I see you have elminated those methods in any case so that seems consistent.

I note also there is some discussion the comments that mod 2 is faster than and 1 - I have not found this to be the case.

@glenkleidon
Copy link

@KimMadsen I made a pull request against your patch-1 branch for converting the dictionary to static.

@mathias-burbach
Copy link

mathias-burbach commented Jul 10, 2021

I am new here and I have not made any contributions yet. But I found a way to improve the current Delphi implementation.

Instead of

procedure TPrimeSieve.ClearBit(Index: Integer);
begin
if (Index mod 2) = 0 then
Exit;
FBitArray[Index div 2] := False;
end;

we could use

procedure TPrimeSieve.ClearBit(const Index: Integer);
begin
if (Index mod 2) = 1 then
FBitArray[Index div 2] := False;
end;

I have observed a 2.1853% increase of passes without the Exit; call.

Sorry if the indention isn't working all that well in this editor.

Salut,
Mathias

@glenkleidon
Copy link

glenkleidon commented Jul 11, 2021 via email

@mathias-burbach
Copy link

Hello Glen,

Thanks your reply. You are right I was not aware of the more recent branch #264.

I have downloaded it and find it extremely educational to compare the old version against the newer version. :-)

If I run the latest branch on my Delphi VMware virtual machine I get to 9046 passes for 32bit.

I wondered if there is a chance to further improve this by using unsigned integers like NativeUInt and convert the passes into NativeUInt too? But that slowed it down slightly. I thought it could help to increment the counter on less bytes, but it seems Inc works best on dword.

So with my limited assembler knowledge it seems that there is not much more that I can contribute.

But thanks for all the improvements anyhow and giving me the chance to study them.

Salut,
Mathias

@glenkleidon
Copy link

glenkleidon commented Jul 11, 2021 via email

@glenkleidon
Copy link

glenkleidon commented Jul 11, 2021 via email

@rbergen
Copy link
Contributor

rbergen commented Aug 2, 2021

@KimMadsen Do you still want to pursue getting this PR merged? The same question applies to #281.

@rbergen
Copy link
Contributor

rbergen commented Aug 7, 2021

Closing this based on comments made in #281.

@rbergen rbergen closed this Aug 7, 2021
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.

4 participants