Writing Faster Python 3

Did you know that Python preallocates integers from -5 to 257? Reusing them 1000 times, instead of allocating memory for a bigger integer, can save you a couple milliseconds of code’s execution time. If you want to learn more about this kind of optimizations then, … well, probably this presentation is not for you 🙂 Instead of going into such small details, I will talk about more “sane” ideas for writing faster code.

After a brief overview of different levels of optimization and how they work in Python, I will show you simple and fast ways of measuring the execution time of your code and finally, discuss examples of how some code structures could be improved.

You will see:

* The fastest way of removing duplicates from a list
* How much faster your code is when you reuse the built-in functions instead of trying to reinvent the wheel
* What is faster than the “for loop”
* If the lookup is faster in a list or a set
* When it’s better to beg for forgiveness than to ask for permission

PUBLICATION PERMISSIONS:
Original video was published with the Creative Commons Attribution license (reuse allowed). Link: https://www.youtube.com/watch?v=6P68IBou_cg

You might be interested in

LEAVE YOUR COMMENT

Your email address will not be published. Required fields are marked *

eos
EOS (EOS) 0,547824 5,03%
aave
Aave (AAVE) 61,91 1,17%
the-graph
The Graph (GRT) 0,082626 2,47%
kusama
Kusama (KSM) 17,64 2,32%
waves
Waves (WAVES) 1,44 2,56%
dash
Dash (DASH) 25,70 1,95%
bitcoin
Bitcoin (BTC) 26.289,66 0,33%
ethereum
Ethereum (ETH) 1.565,24 0,96%
cardano
Cardano (ADA) 0,244931 1,87%
tether
Tether (USDT) 0,955050 0,04%
xrp
XRP (XRP) 0,511505 4,65%
solana
Solana (SOL) 21,94 4,83%
polkadot
Polkadot (DOT) 3,84 1,58%
usd-coin
USDC (USDC) 0,955050 0,06%
dogecoin
Dogecoin (DOGE) 0,058309 0,76%
uniswap
Uniswap (UNI) 4,11 2,01%
terra-luna
Terra Luna Classic (LUNC) 0,000056 2,92%
litecoin
Litecoin (LTC) 61,25 2,64%
chainlink
Chainlink (LINK) 7,35 2,30%
bitcoin-cash
Bitcoin Cash (BCH) 218,65 1,44%
algorand
Algorand (ALGO) 0,094087 2,74%
matic-network
Polygon (MATIC) 0,537003 1,76%
stellar
Stellar (XLM) 0,107435 1,57%
cosmos
Cosmos Hub (ATOM) 6,65 3,49%
filecoin
Filecoin (FIL) 3,13 0,59%
tron
TRON (TRX) 0,084892 1,14%
ethereum-classic
Ethereum Classic (ETC) 14,87 2,28%
dai
Dai (DAI) 0,954514 0,01%
tezos
Tezos (XTZ) 0,641440 0,47%
monero
Monero (XMR) 142,76 1,87%