5 ms·
Could you give an example of where this would be the case? I write both Python and C++ code all day and I can't think of a single situation where I'd expect bet
by MrScruff 15y ago
Could you give an example of where this would be the case? I write both Python and C++ code all day and I can't think of a single situation where I'd expect better performance from Python than a similar C++ implementation.
- oelewapperke 15y agoActually in this example the non-optimized C++ still beat all other tests, including the heavily optimized ones. This is also my experience in google code jam. Expertly optimized java/python struggles to keep up with non-optimized C++. And C++ has all the conveniences you're used to (like ints-when-value-<2^31-but-auto-change-on-overflow integers).
- ajross 15y agoPython might be a bad example, as the interpreter really isn't terribly fast. But with Javascript, I wouldn't be surprised at all if the same naive implementation of a typical web-ish task (lots of strings, parsing, lots of heap churn) ran faster on V8 than it did compiled from C/C++.
- saucetenuto 15y agoHere's one that bites every c++ newbie at least once (please forgive minor syntactic mistakes, it's been a while): std::vector<LargeStruct> things = GetABunchOfThings(); // Why does this take so long? // Oh well, time to sort std::sort(things.begin(), things.end(), LargeStructComparator()); ...and then your program takes forever and your profiler tells you that 99.9% of your time is spent in LargeStruct's copy constructor. And then you refactor to use pointers and teach the comparator to dereference them, whatever, it's fine, but the naive Python version will just work. Of course, after c++0x becomes widespread this problem will go away. Yay move constructors.
- jongraehl 15y agoBasically correct, except std::sort uses assignment, not copy construction. It's also likely that the optimizer will have GetABunchOfThings construct its result once in the caller's "things". Lambdas are C++0x, so maybe move constructors (another C++0x feature) will be employed instead.