3 ms·
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 onl
by bbojan 4y ago
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.
- SekstiNi 4y agoJust to be sure, you did compile the Rust program using the --release flag?
- bbojan 4y agoYup!
- remuskaos 4y agoDid 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.
- bbojan 4y agoI'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.
- momojo 4y agoAren't most of the python primitives implemented in C?
- alpaca128 4y agoParts 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.
- tomrod 4y agoInteresting! This is usually touted as an antipattern.