change hash function gives up to 22% speedup #14

Open
tigrazone wants to merge 13 commits from unknown repository into master
tigrazone commented 2017-10-30 18:59:46 +00:00 (Migrated from github.com)
No description provided.
edwinyzh commented 2017-10-31 06:17:14 +00:00 (Migrated from github.com)

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

Wow! Is the 22% speedup affects the entire library when executing JS code?
tigrazone commented 2017-10-31 06:35:27 +00:00 (Migrated from github.com)

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.

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 commented 2017-10-31 12:28:25 +00:00 (Migrated from github.com)

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

.Name = .Name +can be changed to add widechars to array and then fast copy to .Name at finish of cycle
data-man commented 2017-10-31 12:47:11 +00:00 (Migrated from github.com)

@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

@tigrazone > Maybe you rewrite my hash function in assembler? Why just assembler? :) Try this: (taken from awesome [blog](http://guildalfa.ru/alsha/) (in russian)) ```pascal 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](http://guildalfa.ru/alsha/node/2) [CRC64 parallel calculation](http://guildalfa.ru/alsha/node/4)
data-man commented 2017-10-31 13:00:29 +00:00 (Migrated from github.com)

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

A few words about Aleksandr Sharahov. See [Fastcode Winner's List Overview](http://fastcode.sourceforge.net/challenge_content/Winners_List_Overview.html)
tigrazone commented 2017-11-03 16:37:29 +00:00 (Migrated from github.com)

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;

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 commented 2017-11-03 16:58:57 +00:00 (Migrated from github.com)

@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 Why do you call it your function? It is called X31Hash and it was invented by Karl Nelson more than 17 years ago.
tigrazone commented 2017-11-03 17:14:17 +00:00 (Migrated from github.com)

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;

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 commented 2017-11-03 17:51:59 +00:00 (Migrated from github.com)

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.

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.
This pull request is broken due to missing fork information.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin unknown repository:unknown repository
git switch unknown repository

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch master
git merge --no-ff unknown repository
git switch unknown repository
git rebase master
git switch master
git merge --ff-only unknown repository
git switch unknown repository
git rebase master
git switch master
git merge --no-ff unknown repository
git switch master
git merge --squash unknown repository
git switch master
git merge --ff-only unknown repository
git switch master
git merge unknown repository
git push origin master
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
BeRo1985/besen!14
No description provided.