The Wayback Machine - https://web.archive.org/web/20210325184347/https://github.com/davepl/Primes/pull/6
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

Get C# to 75% of the C++ perf on my box #6

Open
wants to merge 4 commits into
base: main
from

Conversation

@tannergooding
Copy link

@tannergooding tannergooding commented Mar 25, 2021

On my own box, C++ measures: Passes: 16268, Time: 10.000000, Avg: 0.000615, Limit: 1000000, Count: 78498, Valid: 1

This builds on @EgorBo's PR in #4 and gets the C# version to Passes: 12605, Time: 10.0003958, Avg: 0.0007933673780245934, Limit: 1000000, Count: 78498, Valid: True which is ~75% of the perf of the C++ variant.

The key points are to elide bounds checks and more closely mirror what C++ in terms of types and code used to make it a more fair comparison. C# inherently does things C++ doesn't, like bounds checks.
If the version to version comparisons were to be equally safe (with C++ using things like std::array and doing bounds checking before accesses, eliding where it is statically determined to be "safe"), then C++ wouldn't have such a "clear lead" 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
2 participants