3 ms·
Obviously C/C++/Rust with handwritten state machines could make this way smaller, e.g. under 100 bytes. But at some point there are diminishing returns, and als
by userbinator 8y ago
Obviously C/C++/Rust with handwritten state machines could make this way smaller, e.g. under 100 bytes. But at some point there are diminishing returns, and also developer productivity, bugs, and security are big tradeoffs.
Looking at this another way: you need >20x more memory to achieve the same level of performance as native code in C#. Suddenly the benchmark doesn't look that great anymore.
- karl_p 8y agoIt still will be amortized by your application's data. For example, reading and buffering actual messages. The benchmark literally just has a one byte "buffer" per connection. I threw this benchmark together in a couple of hours pretty easily. The most annoying part was just measuring the RAM :-) But yes, everything is a tradeoff. If you want safety, you pay more - either in RAM, or in cognitive load.
- cwyers 8y ago20x on a toy problem isn't bad, if some portion of the increased memory usage is fixed (in other words, doesn't scale up with the complexity of the app).
- nicoburns 8y agoTrue, on the other hand if C#'s memory usage is reasonable enough that your program isn't memory bound, then it might start looking better again.
- int_19h 8y ago> Looking at this another way: you need >20x more memory to achieve the same level of performance as native code in C#. It's more like, you need 10x more memory with 100x more productivity than C/C++. If you don't care about productivity, however, you can actually write C# as you'd write C, and with a very similar perf profile. You can put everything into structs to avoid heap allocations, for example. You could use stackalloc, which basically gives you fixed-size non-bounds-checked stack-allocated arrays, exactly as in C. You can have pointers that GC knows nothing about, and you can even do arithmetic on them like in C. You can even have type punning unions. And then you can put an API on top of all that which makes it usable with async/await - and write the rest of your code in high-level C#.