News for hackers. Stuff that matters.
Re:Why Is Python Growing So Quickly? by xapata on Thursday September 14, 2017 @01:32PM (#15250332)
One of my clients recently replaced a major chunk of their C++ code with Python and achieved a speedup from multi-hour to sub-millisecond. That's a big win.

Python encourages readable code, which enables smarter algorithms, which ultimately swamps all those little memory optimizations. Oh, and PyPy/Numba/Cython let you get those little optimizations, too.

Re:Why Is Python Growing So Quickly? by dna_polymerase on Thursday September 14, 2017 @01:38PM (#15250400)
In addition to that there are loads of libraries for Python which are written in C, which gives you speed in the right moments.

I think the readable code thing is really really important, too. I can understand other peoples code quicker and learn more about the actual algorithm unlike in C++ where I wonder half of the time about syntactical non-sense and optimizations for certain compiler targets.

Then again, Python and C++ target very different groups and I like both languages for certain things.

Re:Why Is Python Growing So Quickly? by Sohcahtoa82 on Thursday September 14, 2017 @02:00PM (#15250685)
> One of my clients recently replaced a major chunk of their C++ code with Python and achieved a speedup from multi-hour to sub-millisecond.

I'd really like to know what they were doing and how they could do it so wrong that the C++ version took hours while the Python version was faster than a blink of the eye.

Re:Why Is Python Growing So Quickly? by goatlover on Thursday September 14, 2017 @02:47PM (#15251181)
Good question. I did have a situation where looping over a fairly large Pandas dataframe took 12 minutes, but using the underlying numpy values took only 3 seconds. The looping was required to do complicated row and column operations.

Similarly, naybe the C++ code was using an inefficient data structure for a large dataset compared to using something like Numpy.

Re:Why Is Python Growing So Quickly? by xapata on Thursday September 14, 2017 @06:20PM (#15252967)
It had to do with the number of dimensions and combinations that were being looped over. That kind of scale difference generally comes from combinatoric explosion -- exponential or high polynomial time vs linear or log-linear time.

The rewrite realized an approximation was reasonable in place of a more "correct" algorithm.

Note that I'm not saying Python was the cause, but the ease of reading and writing code may have helped the programmer come to this algorithm. Instead of stressing about bugs and deadlines. Algorithm choice seems correlated with language choice, in my experience.

Re:Why Is Python Growing So Quickly? by amelius on Thursday September 14, 2017 @01:49PM (#15250547)
> One of my clients recently replaced a major chunk of their C++ code with Python and achieved a speedup from multi-hour to sub-millisecond.

Code rewrites are often more than a literal translation. They often eliminate old code, and allow to rethink the architecture. So it's really not a surprise that Python code would be faster here. A rewrite to C++ would probably be much faster still.

Re:Why Is Python Growing So Quickly? by xapata on Thursday September 14, 2017 @07:14PM (#15253263)
Perhaps a C++ rewrite would be faster, but it depends on how many of the dependencies you revise to be optimal for this particular task and how much more clever you are than the NumPy authors and a jit-compiler.
Re:Why Is Python Growing So Quickly? by goatlover on Thursday September 14, 2017 @04:10PM (#15252052)
Depending on how heavily the Python code leveraged Numpy.
Re:Why Is Python Growing So Quickly? by xapata on Thursday September 14, 2017 @06:31PM (#15253027)
Oops, typo: sub-second, not sub-millisecond.