| ▲ | eska 2 hours ago | |||||||
I appreciate that you first tried to optimize the original Python code. Idiomatic Python is unfortunately disappointingly slow and not so interesting to compare to. | ||||||||
| ▲ | jerf 2 hours ago | parent | next [-] | |||||||
I often use the rough approximation that Python is 40-50x slower than C. This is what you'll see in the benchmarks. The truly rough thing about Python though is that that is the speed when the code is being written to a benchmark. It is really, really easy to write Python that is multiples slower than that when not writing to a benchmark and just trying to get work done without hyperoptimizing. I did some testing of Python [1] to back some other commentary I was making that compared the time it took to set an attribute repeatedly on a particular instance of an empty class to the time it took to setting it on a subclass of a subclass of a class that had a property setter that was wrapped by a decorator. The latter was about 4.6 time slower than the direct attribute setting, which was itself already ~100x slower than an attribute setting in a static language. And it's not like a three-deep nested class with a property wrapped by a decorator is all that absurd in Python or anything. That's a completely normal case, not some absurd example I made up to skew the test. In practice the 40-50x number is more lower bound than what you can count on. If you are actually using Python's features I think you can easily score another order of magnitude slower without anything jumping out at you as being an obviously bad idea. [1]: https://jerf.org/iri/post/2024/not_about_python_addendum/ | ||||||||
| ||||||||
| ▲ | flockonus 43 minutes ago | parent | prev [-] | |||||||
> not so interesting to compare to Absolutely disagree here, something that is considered good practice is very interesting to compare to! | ||||||||