Print Statements Make Code Slow
a loop with/without print statements is the difference between 2 mins execution time and 2 seconds (5900% more time to execute) please don’t run your code with a lot of print statements unless you’re debugging Tried doing it in a very simple script just for fun, the difference is quite staggering: In large.py: target = open('target.txt', 'w') for item in xrange(4000000): target.write(str(item)+'\n') print item Timing it: gp@imdev1 /tmp$ time python large.py real 1m51.690s user 0m10.531s sys 0m6.129s gp@imdev1 /tmp$ ls -lah target.txt -rw-r--r-- 1 gp gp 39M Nov 8 16:... Now running the same with "print" commented out: gp@imdev1 /tmp$ time python large.py real 0m2.584s user 0m2.536s sys 0m0.040s so i saved $27000/year by removing 10 lines of code this morning they were print() statements
A screenshot of a social media post explains that repeatedly printing output inside a loop can make a program dramatically slower. A code example compares nearly two minutes with print statements to about two seconds without them, leading to the joke that removing ten print statements saved $27,000 per year. It is shared as a humorous reaction to inefficient debugging code or excessive logging.
social media post / публикация в соцсетиcomputer code / компьютерный кодPython script / скрипт на Pythonterminal window / окно терминалаtext editor code block / блок кода в редактореloop / циклprint statement / оператор printfile / файлblack background / чёрный фонwhite text / белый текстupvote counter / счётчик голосовcomment / комментарий
#программирование#programming#python#код#code#print statements#операторы print#отладка#debugging#производительность#performance#медленный код#slow code#цикл#loop#логирование#logging#разработка#development#программист#programmer#технический юмор#tech humor#реакция#reaction#скриншот#screenshot#твит#tweet#мем#meme
- @gentoomemes / 11047 2024-05-02
- Type
- image
- Size
- 314×800 · 54.0 KiB
- Mood
- саркастичный, технический
- Language
- en
- Added