Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Hmm, interesting that single threaded C++ is 25% of Python exec time. It feels like C++ implementation might have area for improvement.

My usual 1-to-1 translations result in C++ being 1-5% of Python exec time, even on combinatorial stuff.



I recently ported some very simple combinatorial code from Python to Rust. I was expecting around 100x speed up. I was surprised when the code ended running only 14 times faster.


Just to be sure, you did compile the Rust program using the --release flag?


Yup!


Parts of Python are implemented in C. For example the standard for loop using `range`. So when comparing Python's performance with other languages using just one simple benchmark can lead to unexpected results depending on what the program does.


Interesting! This is usually touted as an antipattern.


Did you use python specific functions like list comprehensions, or "classic" for/while loops? Because I've found the former to be surprisingly fast, while naive for loops are incredibly slow in python.


I've used list comprehensions where they make sense. But it's a non-trivial (although a simple) program, so there are for loops too.

So I'm using a mix of chain and permutations from itertools, list comprehensions and for loops.


Aren't most of the python primitives implemented in C?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: