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

change hash function gives up to 22% speedup #14

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open

change hash function gives up to 22% speedup #14

wants to merge 13 commits into from

Conversation

tigrazone
Copy link

No description provided.

change hash function to simple and fast *31 function
22% speedup
added benchmark for generate 5000 perfect numbers
fix compile error
really up to 3% speedup
compact code, one module uses.
speed up really to 22%
calc hash and compare with hashed values
@edwinyzh
Copy link

Wow! Is the 22% speedup affects the entire library when executing JS code?

 and change copy of standard functions to original
@tigrazone
Copy link
Author

not always. 3%-10% speedup when executing JS code.
Maybe you rewrite my hash function in assembler?
bottlenecks is copy functions, .Name = .Name + and balansed tree not too fast.
I also change BESENANSIPos to Pos, BESENANSIPosChar to Pos, BESENANSIUpperCase to UpperCase and BESENANSITrim to Trim. It give me -500 bytes in exe ;-)
Look at my last commit.

@tigrazone
Copy link
Author

.Name = .Name +can be changed to add widechars to array and then fast copy to .Name at finish of cycle

@data-man
Copy link

@tigrazone

Maybe you rewrite my hash function in assembler?

Why just assembler? :)
Try this: (taken from awesome blog (in russian))

function ShaPerfectHashStr(const s: RawByteString): integer;
var
  i: integer;
begin;
  Result:=0;
  for i:=0 to Length(s)-1 do Result:=(Result + ord(s[i+1]) + 1507220783) * 1041204193;
end;

Well, and assembler :)
CRC32 parallel calculation
CRC64 parallel calculation

@data-man
Copy link

data-man commented Oct 31, 2017

A few words about Aleksandr Sharahov. See Fastcode Winner's List Overview

@tigrazone
Copy link
Author

my hash function is simpler and faster
function thrHashKey(const Key:TBESENString):TBESENHash;
var i,h:longword;
begin
if length(key)<1 then
begin
result:=0;
exit;
end;

h:=ord(Key[1]);
for i:=2 to length(Key) do begin
h:=(h shl 5) - h + ord(Key[i]);
end;

result:=h;
end;

@data-man
Copy link

data-man commented Nov 3, 2017

@tigrazone
Why do you call it your function?
It is called X31Hash and it was invented by Karl Nelson more than 17 years ago.

@tigrazone
Copy link
Author

yes! it's X31Hash. same function used in TFPHashList
Function FPHash(const s:shortstring):LongWord;
var
p,pmax : PChar;
begin
{$push}
{$Q-}
Result:=0;
p:=@s[1];
pmax:=@s[length(s)+1];
while (p<pmax) do
begin
Result:=LongWord(LongInt(Result shl 5) - LongInt(Result)) xor LongWord(P^);
Inc(p);
end;
{$pop}
end;

@data-man
Copy link

data-man commented Nov 3, 2017

Well, then the FP developers also do not respect the merits and work of other people.
This is not accepted in the open source community.
Honest people are not accepted that way.
And you had impudence to name a function by your name.

@BeRo1985 don't merge this PR, please.

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.

3 participants