Last active
September 22, 2021 00:58
-
-
Save mawillcockson/15a39ba9da0e0bdc20436069ae2bf24a to your computer and use it in GitHub Desktop.
Do short identifiers make python run faster?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
set -eu | |
A=0 | |
IDENTIFIER="$(python3 -c 'print("a" * 100_000, end="")')" | |
export IDENTIFIER | |
echo "IDENTIFIER is ${#IDENTIFIER} characters" | |
for python_version in python3.6 python3.7 python3.8 python3.9; do | |
echo "${python_version}" | |
printf 'short identifier -> ' | |
"${python_version}" -m timeit \ | |
-s "a = 1" \ | |
-s "${IDENTIFIER} = 1" \ | |
-s "def short(): a + 1" \ | |
-s "def long(): ${IDENTIFIER} + 1" \ | |
"short()" | |
printf 'long identifier -> ' | |
"${python_version}" -m timeit \ | |
-s "a = 1" \ | |
-s "${IDENTIFIER} = 1" \ | |
-s "def short(): a + 1" \ | |
-s "def long(): ${IDENTIFIER} + 1" \ | |
"long()" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
no appreciable difference