4 ms·
according to dan saks, who apparently to some people is famous c++ is faster than c (well in the test setup he describes below) https://accu.org/content/conf20
by rjzzleep 9y ago
according to dan saks, who apparently to some people is famous c++ is faster than c (well in the test setup he describes below)
https://accu.org/content/conf2015/DanSaks-Embedded%20Programming%20Death%20Match.pdf https://accu.org/content/conf2015/DanSaks-Embedded%20Program...
Language Design Implementation Relative Performance
either any inline 1 (fastest)
C++ polystate non-inline 1.56 x fastest
C++ bundled non-inline 1.65 x fastest
C polystate non-inline 1.70 x fastest
C bundled non-inline 1.79 x fastest
C++ unbundled non-inline 1.82 x fastest
C unbundled non-inline 1.95 x fastest
He furthermore argued that the biggest mistakes C++ developers did to kill the adoption of C++ for C programmers was to diverge from the previous line of "C++ is a better C" to "if you're using C++ as a better C you're doing it wrong"
https://www.youtube.com/watch?v=D7Sd8A6_fYUI https://www.youtube.com/watch?v=D7Sd8A6_fYUI
(I have no skin in the game, I was just curious to see if it's worth looking at rust for embedded when I came across that talk)
- WalterBright 9y agoOver in D-land we've embraced the concept of using D as a "better C" :-) https://dlang.org/blog/2017/08/23/d-as-a-better-c/ https://dlang.org/blog/2017/08/23/d-as-a-better-c/ This is not in the sense of tossing away C coded programs wholesale and rewriting it in D, but incrementally using D here and there for parts of a C program. That way, you've always got a working, usable program.
- harry8 9y agoif (existsCoffee) writeln("Drink coffee"); http://ddili.org/ders/d.en/if.html http://ddili.org/ders/d.en/if.html Sad that you adopted one of C's worst features. Why? Can you get rid of it and mandate the bracing every block?
- WalterBright 9y agoMy take on C's biggest mistake: https://digitalmars.com/articles/b44.html https://digitalmars.com/articles/b44.html
- harry8 9y agoSure but there is just no reason at all to copy unbraced blocks. All you do is invite bugs for zero benefit. Maybe there are bigger issues with C? But that's a different discussion. I want to know why you copied something as simultaneously horrendous and useless as unbraced blocks? If you just didn't think it through and that's the way languages syntactically similar to C have always done it, ok. I'm sure I've made worse mistakes. But please call it one way or the other.
- humanrebar 9y ago> "if you're using C++ as a better C you're doing it wrong" As far as correctness and safety goes, this is still true. It's difficult to scale systems-level programming to large teams. C++ gives the opportunity for more explicit semantics and more aggressive compile-time checks. C can scale well and can be used safely, but you need to do a lot more through convention (always call xyz_Create and xyz_Destroy in pairs!) and through runtime checks (calls to assert, unit testing). D, Rust, OCaml, and a few other projects are interesting in this space since they provide some of the same benefits as C++ with respect to correctness and safety. Some are plausibly better in theory, though I'm not aware of huge, say, Rust projects that approach the size of huge C++ ones.
- khitchdee 9y agoAgreed. It's the size and type of the project that determines the choice of language more than the newness of the language. C++ was designed to meet the requirements of certain types of projects that were coming into vogue at the time it was designed. It was not a replacement for C. Some of the structural advantages of C++ over C can be achieved in C by using generative programming for example and building in automatic mechanisms to ensure there are no memory leaks for example. In other words, the C++ approach to structuring programs is not the only way to achieve the benefits that that structuring implies. It's just really easy to do it that way.
- humanrebar 9y agoIt's true that generative programming can make up for shortcomings of C. But you're pretty much writing in two languages at that point, C and whatever spec generated the rest of the C code. It's not an apples-to-apples comparison to C++.
- khitchdee 9y agoWell, some parts of the generative programming could be built into a tool and you probably wouldn't have to rewrite a generative program each time. So it's not really writing in 2 languages but using code generation to assist the programming process to reduce potential for error as a more flexible alternative to creating fixed constructs in a purpose built language.