2 ms·
Every language has these. In C/C++, which is faster: i++; or ++i; These days, a decent compiler will output the same machine code, but it wasn't always tru
by Sohcahtoa82 3y ago
Every language has these.
In C/C++, which is faster:
i++;
or
++i;
These days, a decent compiler will output the same machine code, but it wasn't always true, and ++i was faster.
And really, the "dict() vs {}" performance issue can probably get fixed by the interpreter, but it's such a micro-optimization that it's not worth the time and effort.
- __loam 3y agoI think C++ actually has a very similar problem here, the complexity is worse but I'd bet the runtime isn't an issue because, as you said, the compiler should handle it. The specific problem here is that python has multiple ways to do things that seem pretty much equivalent but that have different run times. Another example is for loops, list comprehensions, and map. All of these things iterate over a collection but all have different run times. That does not make much sense imo.
- mr_toad 3y ago> All of these things iterate over a collection but all have different run times. List comprehensions return a list, and map returns something, while a for loop doesn’t necessarily return anything. I’d expect the overhead of constructing the returned object has an impact on performance.