4 ms·
Benchmark it, it won't be any faster. Using the if statement: Execution time: 0.00648 seconds Using the min function directly: Execution time: 0.02298 seconds
by ipsum2 2y ago
Benchmark it, it won't be any faster.
Using the if statement: Execution time: 0.00648 seconds
Using the min function directly: Execution time: 0.02298 seconds
Using the min function with an intermediate variable: Execution time: 0.02959 seconds
- necovek 2y agoHow about using the `min` builtin directly over the entire list?
- winrid 2y agoSure, let's benchmark it :) It is consistently around 8% to 15% faster on 3.10.12 and 3.11 for me. On 3.12.5 (latest) I seem to get the same result. https://www.online-python.com/B6AgKW5zod https://www.online-python.com/B6AgKW5zod (please copy the code to your local to not ddos this site :D)
- otteromkram 2y agoI agree with you. It's a weird quirk of Python where localization is more efficient.