TGTGInsighttelegram intelligenceLIVE / telegram public index
← Python Заметки

TGINSIGHT SIMILAR POSTS

Најди сличен содржај

Изворен канал @pythonotes · Post #32 · 7 фев.

Скорее всего уже слышали, что складывать строки через + это плохая практика. Падение производительности, и всё такое. Без лишних слов, давайте измерять: from timeit import timeit def t1(): # складываем 10 строк через + из переменной t = 'text' for _ in range(1000): s = t + t + t + t + t + t + t + t + t def t2(): # склеиваем список строк через метод join arr = ['text'] * 10 for _ in range(1000): s = ''.join(arr) def t3(): # складываем через + но не из переменной а непосредственно инлайн объекты for _ in range(1000): s = 'text' + 'text' + 'text' + ... # всего 10 раз Теперь каждую строку склейки запустим по 10М раз >>> timeit(t1, number=10000) 0.21951690399964718 >>> timeit(t2, number=10000) 1.4978306379998685 >>> timeit(t3, number=10000) 0.2213820789993406 Хм, а нам говорили что через "+" это плохо и медленно ))) 😁 Тут стоит учитывать, что речь идёт о склейке множества длинных строк. Давайте изменим условия: def t4(): t = 'text'*100 for _ in range(1000): s = t + t + t + t + t + t + t + t + t def t5(): arr = ['text'*100] * 10 for _ in range(1000): s = ''.join(arr) def t6(): for _ in range(1000): s = 'text'*100 + 'text'*100 + ... # всего 10 раз >>> timeit(t4, number=10000) 12.795130728000004 >>> timeit(t5, number=10000) 2.642637542999182 >>> timeit(t6, number=10000) 0.2184546610005782 Вот, уже другой разговор, сразу видна разница, в среднем в 6 раз. Но погодите, почему последний тест t6() по скорости такой же как и t3()? Ведь строки теперь в 100 раз длиннее! Это вопросы оптимизации кода, какие простые изменения ускоряют или замедляют выполнение программы. Мы столкнулись с примером обхода обращения к переменной. Например, именно так работает директива #define в С++, во время компиляции подставляя значение переменной вместо ссылки на неё. В Python это тоже работает, но часто ли вы сможете встретить такой способ работы со строками? К сожалению, способ почти только теоретический. В целом, тесты показали то, что мы хотели. Делаем выводы самостоятельно. Полный листинг 🌍 #tricks

Резултати

Пронајдени 4 слични објави

Пребарај: #console

当前筛选 #console清除筛选
GitHub Trends

@githubtrending · Post #15135 · 10.09.2025 г., 13:00

#javascript#ansi#ansi_escape_codes#chalk#cli#color#commandline#console#javascript#strip_ansi#terminal#terminal_emulators Chalk is a popular Node.js tool that lets you easily add colors and styles to text in the terminal, making your console output clearer and more attractive. It supports many colors, including 256 and truecolor (millions of colors), and allows you to combine and nest styles like bold, underline, and background colors. Chalk auto-detects if your terminal supports colors and works without adding dependencies or changing built-in string behavior. You can create custom themes and use template literals for dynamic, colorful logs. This helps you highlight important information in your terminal output, improving readability and debugging. Chalk is reliable, actively maintained, and widely used in many projects. https://github.com/chalk/chalk

GitHub Trends

@githubtrending · Post #15000 · 27.07.2025 г., 12:00

#markdown#android#bsd#cheatsheet#cheatsheets#command_line#console#documentation#examples#hacktoberfest#help#linux#macos#man_page#manpages#manual#osx#shell#terminal#tldr#windows The tldr-pages project offers simple, easy-to-understand help pages for command-line tools, focusing on practical examples rather than long, complex manuals. It’s great if you’re new to the command line or forget command options, as it shows the most useful commands clearly. You can access these pages through various clients or online without installing anything. This saves you time and frustration by giving quick, clear guidance on common tasks, making it easier to learn and use command-line tools effectively. Plus, you can contribute by adding or improving pages yourself. This helps you and others get fast, practical help with commands[1][4]. https://github.com/tldr-pages/tldr

跑跑資訊站 KartInfo

@KartInfoTW · Post #470 · 10.01.2023 г., 02:01

🚀《跑跑卡丁車:飄移》全平台正式開放下載,同時事前預約活動也即將在 1/12 結束, 更多事前預約活動資訊以及遊戲下載連結立即點擊查看 👇 🔥 完整遊戲資訊:https://kinf.cc/wrrUP ⭐️ 飄移未來發展:https://kinf.cc/E45Ty ▶️ 追蹤 Google 新聞:https://kinf.cc/gn ▶️ 立即加入 Discord:https://kinf.cc/dc #跑跑卡丁車#KartRider#飄移#跑跑飄移#KartRiderDrift#KartDrift#事前預約#季前賽#PreSeason#公測#PublicBeta#下載#Download#PC#Windows#Nexon#Steam#Console#XBOXOne#PS4#Mobile#AppStore#GooglePlay#iPad