Skip to content
This repository has been archived by the owner on Sep 26, 2021. It is now read-only.

Latest commit

 

History

History
8 lines (6 loc) · 828 Bytes

speed_ups.md

File metadata and controls

8 lines (6 loc) · 828 Bytes

##Table of ways to speed up your code

Instead of ... Do Why When to use the slower code
readlines() Loop over the file readlines reads in the whole file at once, which takes a lot of memory. When you loop, you can start processing the data immediately, which saves time, and allows you to save smaller subsets of the file in memory, if you wish When you really quick want to visualize the file at the interpreter
declaring and making a list list comprehension These run in the C language, which makes them faster For readability. If your code will be read by novices, it might be best to keep it simple
open with open this is not a speed-up per se, but prevents us from having to remember to close our loops Again, readability.