4 ms·
I think benchmarking C vs C++ vs Rust must only really be useful for researchers. They’re all making a similar tradeoff for performance: forcing you to consider
by jolux 6y ago
I think benchmarking C vs C++ vs Rust must only really be useful for researchers. They’re all making a similar tradeoff for performance: forcing you to consider how you use memory. Does anyone work in a field where the performance difference between these specific three platforms matters? I’m genuinely curious. Edit: also, if you could explain briefly why and what makes particular choices out of the three unsuitable, that would be awesome too.
- jandrewrogers 6y agoIt matters for real-world software development, though the reason may not be intuitive. In theory, for any particular bit of software, you can write code in any of these three languages that has nearly identical performance. In practice, the complexity of expressing equivalent performance can vary considerably depending on what you are trying to do. There are finite limits to the complexity cost developers are willing to pay for performance. Because the cost in each of these three languages is different to express some thing, sometimes there will be a threshold where in one or more of these languages most developers will choose a less optimal design. This manifests as practical performance differences in real software even though in theory they are equally expressive with enough effort. This comes with another tradeoff. Efficient expressiveness relative to software performance comes at a cost of language complexity. C is a simple language that has enough efficient expressiveness for simple software architectures. C++ is at the extreme opposite; you can do mind-boggling magic with its metaprogramming facilities that can express almost anything optimally but god help you if you are trying to learn how to do this yourself. Rust sits in the middle; much more capable than C, not as expressive as C++. This suggests the appropriate language is partly a function of the investment a developer is willing to make in learning a language and what they need to do with it. Today, I use modern C++ even though it is a very (unnecessarily) complex language and write very complex software. Once you pay the steep price of learning C++ well, you acutely feel the limitations of what other languages can't express easily when it comes to high performance software design. I used to write a lot of C. It still has critical niches but not for high-performance code in 2021, giving up far too much expressiveness. C++17/20 is incredibly powerful but few developers really learn how to wield that power, though usage of it has been growing rapidly in industry as scale and efficiency have become more important. Rust is in many ways an heir apparent to C and/or Java, for different reasons. Or at least, that is how I loosely categorize them in my head, having a moderate amount of contact with all three. They all have use cases where you probably wouldn't want to use the others.
- steveklabnik 6y ago> In practice, the complexity of expressing equivalent performance can vary considerably depending on what you are trying to do. Yep. Rust's safety means that in some cases, you can be more aggressive because you know the compiler has your back. And in other cases, it makes harder things tractable. The example of Stylo is instructive; Mozilla tried multiple times to pull the architecture off in C++, but couldn't manage to do it until Rust.
- jolux 6y agoThis is a fantastic comment and I think it gives me a much better understanding of the tradeoffs here. It seems like which is the best choice depends a lot on what you're trying to express and how well the tool fits the problem you're trying to solve, and a lot less on what the absolute capabilities of a given language are.
- klysm 6y agoYeah, databases
- JimBlackwood 6y agoCould you elaborate a little? I’d be interested in this answer
- jandrewrogers 6y agoAll three languages are different enough that depending on the language you use it fundamentally alters your database architecture to better fit the mechanics of the language. Databases have a very high levels of internal complexity naturally, so there is a strong incentive to align the design with what the language can express without adding substantially more complexity. I work on database engines and the impact of language choice on the design, architecture, and implementation of database engines is very evident. In the specific case of database engines, these differences in design can have a very large performance impact.
- steveklabnik 6y agoI think what's most interesting about your comment is the assumption that the three are in the same ballpark. You're not wrong, but it just reminds me of how far we've come. That is, the key is not "which of these three can eke out the last tiny ounce of things," but that Rust has successfully landed across that gap you see in the graph. That it's "(C/C++/Rust) vs everything else" is in of itself an interesting result. You can see some skepticism of the premise elsewhere in this thread, even.
- jolux 6y ago>You can see some skepticism of the premise elsewhere in this thread, even. Heh, well. The downvotes are clearly trying to tell me something, though I'm not sure what. I can guess. I assumed that this was something widely agreed upon at this point but clearly I assumed incorrectly. I think ATS is in that category too but it was removed from the benchmarks game at some point. It's also vastly more esoteric and complicated than Rust is from my limited knowledge. Perhaps someday Zig will get there as well. I wouldn't have expected that this niche would ever see so much exploration, as C and C++ were the only game in town for so long.
- steveklabnik 6y agoYeah I mean, to be clear I believe you are right and am pretty surprised you were downvoted. It happens I guess.
- ghostwriter 6y ago> It's also vastly more esoteric and complicated than Rust is from my limited knowledge. I doubt that ATS is more complicated than Rust at on-par feature comparison. It gets more complex only when you reach for a larger set of static constraints you can express in ATS, that are unavailable in Rust: things like dependent types and complete formal proofs that you don't need a separate language for. It feels esoteric only because those features in such low level languages are extremely rare. Also, consider the amount of effort you need to spend on learning a new toolchain (Rust), whereas ATS seems like a plugin/extra compilation step on top of your regular and familiar C toolchain.
- kzrdude 6y agoIt's mostly an exercise that's useful for Rust: Internally, to prove that "it works"* and externally, to make a credible name for Rust. (*) of course part of the output is also looking at the Rust code and evaluating style and `unsafe`-wise what the price for winning was.
- pixel_fcker 6y agoGraphics software.
- londons_explore 6y agoI do some graphics stuff. As soon as you get to "this chunk of code needs to be run for every pixel of every 4k frame at 60fps", suddenly the number of clock cycles and registers matters... Some of my platforms don't have GPU's, so it really is squeezing everything possible out of the language and compiler...
- mrec 6y agoI'm curious, what platforms support 4K output but don't have any kind of GPU?
- londons_explore 6y agoAWS... When you're cheap and don't want to pay for a GPU. Or a bunch of other cloud providers that don't support GPU's at all.
- djeiasbsbo 6y agoI do audio stuff and it is the same there. DSP is easy until it has to be in real time and there can only be minimal latency...