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

Marvin #114

Merged
merged 3 commits into from
Aug 15, 2018
Merged

Marvin #114

merged 3 commits into from
Aug 15, 2018

Conversation

adamsitnik
Copy link
Member

Fixes #44

The original CoreFX benchmarks have it's own copy of Marvin and benchmark the copy. Which needs to be kept in sync manually. I think that we should avoid that.

As @ViktorHofer explained this was because the Marvin class is internal and to make it public we would need to go through API review.

IMHO the best we can do right now is to benchmark string.GetHashCode which is just a call to Marvin.ComputeHash.

It also allows us to compare string.GetHashCode for .NET and .NET Core, where due to security reasons we have regressed the performance https://github.com/dotnet/corefx/issues/30994

@jorive @ViktorHofer what do you think?

dotnet run -c Release -f netcoreapp2.1 -- -f *Hashing* --clr --core21 --join

Method Runtime BytesCount Mean
ComputeHash Clr 10 5.785 ns
ComputeHash Core 10 5.541 ns
ComputeHash Clr 100 28.601 ns
ComputeHash Core 100 39.793 ns
ComputeHash Clr 1000 273.594 ns
ComputeHash Core 1000 381.198 ns
ComputeHash Clr 10000 2,713.600 ns
ComputeHash Core 10000 3,804.547 ns

public void Setup() => _string = new string(Enumerable.Repeat('a', BytesCount / (sizeof(char)/ sizeof(byte))).ToArray());

[Benchmark]
public int ComputeHash() => _string.GetHashCode();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name of the benchmark here would be System.Hashing.ComputeHash. Would it make more sense to be called GetHashCode instead? Or something more descriptive?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is that GetHashCode method exists in the base class (object) so we would need to override the GetHashCode method and the benchmark would include the virtual method invocation cost.

I was also trying to find better class name, but:

  1. I can't call it Marvin because such type exists, and for .NET and .NET Core 2.0- the implementation was not Marvin algo.
  2. The HashCode name is taken by existing type

I am open to better ideas, I just run out of name ideas ;)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe something like System.Hashing.GetDefaultStringHashCode ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe GetStringHashCode ?

@adamsitnik adamsitnik merged commit 1377173 into dotnet:master Aug 15, 2018
@adamsitnik adamsitnik deleted the marvin branch October 17, 2018 15:04
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.

2 participants