3 ms·
I would be surprised if even non-idiomatic CPython could be as fast as C. Even apart from GC, every function call and property access is many C function calls u
by weberc2 9y ago
I would be surprised if even non-idiomatic CPython could be as fast as C. Even apart from GC, every function call and property access is many C function calls under the hood. I imagine the other languages listed share similar (though less dramatic) issues (Go has bounds checking while C does not, for example).
- alkonaut 9y agoYes, obviously all the "can be as fast as C" is modulo safety switched off, and using static calls. If bounds checks aren't elided and dynamic calls aren't JIT'ed into single jumps just like a C function - then you can't match C. Which is why in most languages, you have to effectively write C (in that language). Not even sure if it's possible in (C)Python, but in C# it effectively means using a lot of "unchecked" blocks, pointers, etc, obviously skipping any interfaces or other vtable lookups etc. The C# you end up with (only structs and no classes, no heap allocation, lots of raw pointers, lots of unchecked and unsafe etc ) will resemble C a lot
- pjmlp 9y agoQuite true, but the big difference is that you just have to write "C like" code in a specific code path, ideally after validating it with a profiler. In a language like C that isn't an option, and 100% of the code might be unsafe thanks to UB.
- alkonaut 9y agoRight. I'm very happy to see these low level Span<T> things enter C# so it's a much nicer integration than it was in the past when the only option was to just offload the inner loop to a C library. But even that (Writing 10% of your app in C) is a much better proposition than writing all of it in C.