4 ms·
I get around 0.07 seconds without the write in C++ and the same in Python (good call though). I agree that in pure Python it'd be slower, but realistically why
by joshvm 11y ago
I get around 0.07 seconds without the write in C++ and the same in Python (good call though).
I agree that in pure Python it'd be slower, but realistically why would you do that? Unless you work somewhere where you're forced to write your own libraries... but even then you could still implement your own.
- Someone 11y agoIf you only removed the write and not the reads from the timing, I would guess the reads (even with warm caches) still dominate the time. And you would want to do it in pure Python if you want to answer the question "how fast can we make interpreted Python?". Using C extensions for that is cheating, as it isn't Python and it isn't interpreted. You don't answer the question "how fast can you run?" With "30 km an hour, using a bicycle", either. If you make those images large enough (and I guess 2k x 2k is large enough), any language that uses OpenCV to do the job will give results in the same ballpark. For example, you can make the difference between Python implementations that can call OpenCV as small as you want it.
- RussianCow 11y agoNot the parent, but I think the point is that, in the real world, the vast majority of use cases for which Python is slow are ones where you would use an existing library written in a lower-level language. So questions like "How fast can we make matrix multiplication in Python?" are irrelevant for the vast majority of Python developers because NumPy exists, and it's always going to be faster than anything you can write in pure Python.
- joshvm 11y agoIn Ipython %timeit gives 4.3ms per loop, just on a-b. In C++ it's about the same. I agree that the question is valid - making vanilla Python faster is cool. My point was that this particular example (image processing) was flawed, because it's not something a sane person would ever do in pure Python.
- Someone 11y ago"In Ipython %timeit gives 4.3ms per loop, just on a-b. In C++ it's about the same." Of course it is about the same. Except for function entry and function exit, which should be a few thousand instructions, at the most, it runs the exact same instruction sequence (if you are using identical versions, compiler and compiler flags) If you want an easily measurable difference, use way smaller images, and make a few thousand or even a few million calls, or look at the python sources to see how efficiently it calls into C.