How many lines of C it takes to execute a + b in Python
codeconfessions.substack.com
How many lines of C it takes to execute a + b in Python
1–10 of 224 posts
Re: How many lines of C it takes to execute a + b in Python
#2Re: How many lines of C it takes to execute a + b in Python
#3What's the answer?
Or, the generic, useless but correct, answer: it depends (as the linked article said, too)
Re: How many lines of C it takes to execute a + b in Python
#4They claimed that the hash function was used constantly —e.g. 11 times in print("hello world")—because it's used to look up object properties.
Apparently the default implementation is not optimized for performance but for security, just in case the software is exposed to the web. None of my Python programs are, so assuming all this is true, I'd much prefer to have a "I'm offline, please run twice as fast!" flag (or env variable).
Re: How many lines of C it takes to execute a + b in Python
#5Re: How many lines of C it takes to execute a + b in Python
#6A while back someone posted their patch to cpython where they replaced the hash function with a fast one and claimed this dramatically sped up the whole Python runtime. They claimed that the hash function was used constantly —e.g. 11 times in print("hello world")—because it's used to look up object properties. Apparently the default implementation is not optimized for performance but for security, just in case the so…
https://docs.python.org/3/using/cmdline.html#envvar-PYTHONHA...
The original issue: https://bugs.python.org/issue13703
Re: How many lines of C it takes to execute a + b in Python
#7Re: How many lines of C it takes to execute a + b in Python
#8Sounds like it would be easier to just use C anyway.
The whole point of high level languages is that you put in effort upfront to make everyone elses job easier.
By you logic, using machine code directly onto toggle switches is easiest. No assembler to write, no test editor to write.....
Re: How many lines of C it takes to execute a + b in Python
#9A while back someone posted their patch to cpython where they replaced the hash function with a fast one and claimed this dramatically sped up the whole Python runtime. They claimed that the hash function was used constantly —e.g. 11 times in print("hello world")—because it's used to look up object properties. Apparently the default implementation is not optimized for performance but for security, just in case the so…
> The default hashing algorithm is currently SipHash 1-3, though this is subject to change at any point in the future. While its performance is very competitive for medium sized keys, other hashing algorithms will outperform it for small keys such as integers as well as large keys such as long strings, though those algorithms will typically not protect against attacks such as HashDoS.
https://doc.rust-lang.org/std/collections/struct.HashMap.htm...
However, Rust also lets you pick or implement your own hash algorithm if you want to optimise for your usecase.
Re: How many lines of C it takes to execute a + b in Python
#10Sounds like it would be easier to just use C anyway.