Remix.run Logo
throwaway13337 2 days ago

C# is definitely fast.

There are some benchmark games that I relied on in the past as a quick check and saw it as underwelming vs rust/c++.

For example:

https://benchmarksgame-team.pages.debian.net/benchmarksgame/...

We see that the fastest C# version is 6 times slower than the rust/c++ implementation.

But that's super deceiving because those versions use arena allocators. Doing the same (wrote this morning, actually) yielded a ~20% difference vs the fastest rust implementation.

This was with dotnet 9.

I think the model of using GC by default and managing the memory when it's important is the sanest approach. Requiring everything to be manually managed seems like a waste of time. C# is perfect for managing memory when you need it only.

I like rust syntactically. I think C# is too object-oriented. But with a very solid standard lib, practical design, good tools, and speed when you need it, C# remains super underrated.

anonymars 2 days ago | parent | next [-]

Even way back when: https://devblogs.microsoft.com/oldnewthing/20060731-15/?p=30...

> The fact that Rico Mariani was able to do a literal translation of the original C++ version into C# and blow the socks off it is a testament to the power and performance of managed code. It took me several days of painful optimization to catch up, including one optimization that introduced a bug, and then Rico simply had to do a little tweaking with one hand tied behind his back to regain the lead. Sure, I eventually won but look at the cost of that victory

duncans 2 days ago | parent [-]

Unrelated, but Microsoft should be ashamed that most of the links in that blog no longer work.

tialaramex 2 days ago | parent [-]

I was actually surprised much of the material still exists - though the links don't work. Microsoft performs so much needless self-vandalism and I know some things I care about are gone.

Which just reminded that yeah, all the links I'd made to Raymond Chen's "The poor man's way of identifying memory leaks" no longer work. The Rust implementation is less than four years old, but its link (which worked) now does not. -sigh-

Tempting to go reconstruct that performance improvement "fight" in Rust too. Maybe another day.

andix 2 days ago | parent | prev | next [-]

I really liked reading this article: Writing high performance F# code https://www.bartoszsypytkowski.com/writing-high-performance-...

It more or less tells you to unlearn all functional and OOP patterns for code that needs to be fast. Just use regular loops, structs and mutable variables.

igouy a day ago | parent | prev | next [-]

> There are some benchmark games that I relied on in the past as a quick check …

Try looking at the "transliterated line-by-line literal" programs:

https://benchmarksgame-team.pages.debian.net/benchmarksgame/...

> But that's super deceiving because …

… that's labelled [ Contentious. Different approaches. ]

Try removing line 11 from

https://benchmarksgame-team.pages.debian.net/benchmarksgame/...

bn-l 2 days ago | parent | prev [-]

You summarise it perfectly. Exactly my thoughts as well.

Imagine if we had something with rust syntax but csharp’s support and memory management trade off with escape hatch