67 ms·
That isn't quite true. Swift will be using LLVM as a code generator, but because it will use ARC (a form of garbage collection), it will still end up slower th
by Jweb_Guru 12y ago
That isn't quite true. Swift will be using LLVM as a code generator, but because it will use ARC (a form of garbage collection), it will still end up slower than C++ in many benchmarks. That's not the only example, of course--while LLVM helps immensely, it's not a miracle worker and the original language semantics do make a difference.
- pjmlp 12y agoThis is not true, as Swift ARC is supported by the compiler itself, whereas C++ ARC are library based without any compiler supporter. So a Swift compiler will be able to optimize away ARC calls deemed unnecessary via dataflow optimizations, which a C++ cannot apply.
- dbaupp 12y agoI think C++ give you many more tools to avoid using "ARCs", e.g other smart pointers, not needing smart pointers at all etc.
- pjmlp 12y agoNot using smart pointers is "memory leaks and security exploits" land. RAII is great, but not when dealing with shared data structures. So I lack to see how it can be better. Note that I am a big C++ fan since the C++ARM days, but I am also aware of many of its warts.
- dbaupp 12y agoI just meant you don't need necessarily need pointers at all, since you put things directly onto the stack (or into vectors/your favourite data structure), no need for additional indirection. (Maybe Swift offers this too, but it's certainly something C++ excels at.)
- pjmlp 12y agoFunny to see stack allocation mentioned as C++ strong feature, when so many languages offer it. Maybe this is a side effect of scripting languages and VM implementations going mainstream.
- dbaupp 12y agoPlease, be direct with your criticisms of me rather than just implying them. What other commonly used languages offer pointerlessness to the same degree as C++? Rust, for sure. Not C as there are no generics, making allocations + void* and simplistic data structures like linked lists more common than necessary. Maybe D but AIUI there is some struct/class difference that forces GC allocation for classes. What else? (Also, please read my original comment properly, I was not just talking about "stack allocation".)
- pjmlp 12y agoI am just answering about placing data into the stack, and that is offered by all descendents of Algol/Pascal/CLU/Mesa/Modula/Ada/... family of languages. You can place data in the stack in all of them. Quite a few of them allow for generics, starting with CLU. Ada also offers RAII, although a bit more verbose than C++ way of doing it. All of them allow reference arguments, hence no need for pointers for output parameters.
- dbaupp 12y agoRAII is totally irrelevant to this discussion, and I clearly said I was not just talking about placing data on the stack. > All of them allow reference arguments, hence no need for pointers for output parameters. I wasn't very clear, the use of a C-style pointer is irrelevant: if it is being used as a reference (i.e. not owning, no need for clean-up/deallocation), then it counts as a reference. I was using the Rust terminology where 'pointer' mostly refers to 'smart pointer'.
- deleted 12y ago[deleted]
- rsynnott 12y ago> but because it will use ARC (a form of garbage collection), it will still end up slower than C++ in many benchmarks Well, depends on the C++. ARC is reference counting behind the scenes; in Objective C and Swift, the compiler inserts retains and releases as appropriate. A lot of C++ code also uses reference counting a fair bit; that's what shared_ptr is for, for instance.