smarr / are-we-fast-yet

Are We Fast Yet? Comparing Language Implementations with Objects, Closures, and Arrays
Other
334 stars 36 forks source link

Add C# language #65

Open jfheins opened 2 years ago

jfheins commented 2 years ago

Hi, I thought you might like to add C# to the mix. I used .net 6 so it should be cross platform and run under linux, mac and windows.

If you think C# is a valuable addition, I will continue to port the java benchmarks over. Maybe 2 questions on the code I already wrote:

Just trying to get a feeling for your goals before I tacke the other benchmarks.

smarr commented 2 years ago

Hi @jfheins, yes, the C# benchmarks would be very valuable.

I do have some initial versions of the following already:

Does "System.Numerics.Vector" count as a undesired data structure? (It does give a 20% speedup)

Yes, I would avoid it. The idea would be to use data structures that are common to "all" languages. So, we would want to restrict ourselves to plain arrays where possible.

For the NBody benchmark, it is also surprising to me that the compiler can't figure it out.

I refactored the momentum calculation to bodies.Aggregate(new Vector(), (m, b) => m + b.Velocity * b.Mass); which uses a lambda but is less identical to java. ok or revert?

When in doubt about these things, I'd suggest to look at the range of choices we make for other languages. Though, I'd probably want to stick with what Java does. I'd also would want to keep each of the coordinate dimensions as a separate property. Your choice to turn them into vectors prevents use to assess the getter/setter performance, which is one of the main bits measured by the NBody benchmark.

jfheins commented 2 years ago

I ported Richards now as well, I think this could go in if style is fine. I saw the csharp branch, should I try to merge the two or would you rather do it yourself?

jfheins commented 2 years ago

I merged your branch in to extend the test suite - I hope that's ok? (The brnach also contained some changes outside of the CSharp folder)

In the Harness, I added a Dictionary that keeps track of all known Benchmarks, this might be a tad longer but it is also less "magic" than using Reflection so I'd expect more maintainable for you. (Reflection was easy to break with the namespaces)

smarr commented 2 years ago

I did rebase the PR and started setting up ReSharper as well as basic compiling and running on GitHub Actions. May try to look at the current benchmarks, some style issues.

nikolahua commented 1 year ago

@smarr Is this PR eligible to merge?

smarr commented 1 year ago

@smarr Is this PR eligible to merge?

Why do you ask? I had started the last missing benchmark, Havlak, a while ago, but its still not finished. So, the PR is not quite ready yet.

If you would like to contribute, you're very welcome.

If you have a specific use case, it would be great to know, too.

nikolahua commented 1 year ago

@smarr Is this PR eligible to merge?

Why do you ask? I had started the last missing benchmark, Havlak, a while ago, but its still not finished. So, the PR is not quite ready yet.

If you would like to contribute, you're very welcome.

If you have a specific use case, it would be great to know, too.

I have been looking for benchmark suite which is used to measure performance between different versions of .NET runtime for a long time. I've got nothing until I find this answer. However, the results given by this answer seem to be based on the programming language named Oberon. It will become a very valuable benchmark suite for .NET if the C# benchmarks are also added in.

smarr commented 1 year ago

I see. Though, the AreWeFastYet benchmark suite is not perfect for doing comparisons of runtimes of the same language, or rather different versions of the same runtime.

While it can be used for that, it's really just covering a very small part of the runtime system. Thus, one would be better off to have C# benchmarks that are much larger, and test common application behavior.

In the absence of that, finishing up this PR would be a valuable contribution.