are-we-fast-yet icon indicating copy to clipboard operation
are-we-fast-yet copied to clipboard

Add C# language

Open jfheins opened this issue 2 years ago • 8 comments

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:

  • Does "System.Numerics.Vector" count as a undesired data structure? (It does give a 20% speedup)
  • I refactored the momentum calculation to bodies.Aggregate(new Vector<double>(), (m, b) => m + b.Velocity * b.Mass); which uses a lambda but is less identical to java. ok or revert?

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

jfheins avatar Mar 24 '22 20:03 jfheins

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

I do have some initial versions of the following already:

  • Bounce
  • List
  • Permute
  • Queens
  • Sieve
  • Storage
  • Towers

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.

smarr avatar Mar 25 '22 09:03 smarr

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 avatar Mar 27 '22 18:03 jfheins

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)

jfheins avatar Apr 03 '22 07:04 jfheins

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.

smarr avatar Jul 13 '22 23:07 smarr

@smarr Is this PR eligible to merge?

nikolahua avatar Sep 20 '23 02:09 nikolahua

@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.

smarr avatar Sep 20 '23 08:09 smarr

@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.

nikolahua avatar Sep 20 '23 15:09 nikolahua

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.

smarr avatar Sep 20 '23 15:09 smarr