3 ms·
> One of the other differences is that Python tends to provide higher levels of abstraction than C/C++ code. So, doing something like a set intersection using x
by pfultz2 11y ago
> One of the other differences is that Python tends to provide higher levels of abstraction than C/C++ code. So, doing something like a set intersection using x.intersection(y) may not necessarily be the fastest way.
C++ provides `set_intersection` as well: http://en.cppreference.com/w/cpp/algorithm/set_intersection http://en.cppreference.com/w/cpp/algorithm/set_intersection
- uxcn 11y agoAnd the algorithm version may or may not actually be faster than Python. Essentially, the more abstract and generic things are (like Python), the more you can use them to easily do complex things arcoss different domains quickly. However, the actual concrete implementation is ultimately what matters as far as performance. So, for example, Python may have a better algorithm, but C++ may use the hardware more efficiently.
- pfultz2 11y ago> Essentially, the more abstract and generic things are (like Python) And in C++, it provides the same high-level expressiveness as in Python. > the more you can use them to easily do complex things arcoss different domains quickly. But the advantage of C++ is that those abstractions have almost no overhead. > So, for example, Python may have a better algorithm Actually, C++ has a complexity guarantee for all of its algorithms. > but C++ may use the hardware more efficiently. Well, the brilliance of what Stepanov did was to build general purpose algorithms with out taking away random access capabilities which is beneficial for hardware efficiency(even more so now with modern cpus).