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

Резултати

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

Пребарај: #webhook

当前筛选 #webhook清除筛选
djangoproject

@djangoproject · Post #121 · 25.08.2016 г., 04:39

https://gist.github.com/leandrotoledo/4e9362acdc5db33ae16c # This file is an annotated example of a #webhook based #bot for #telegram. It does not do anything useful, other than provide a quick # template for whipping up a testbot. Basically, fill in the CONFIG # section and run it. # Dependencies (use pip to install them): # - python-telegram-bot: https://github.com/leandrotoledo/python-telegram-bot # - Flask : http://flask.pocoo.org/ # Self-signed SSL certificate (make sure 'Common Name' matches your FQDN): # $ openssl req -new -x509 -nodes -newkey rsa:1024 -keyout server.key -out server.crt -days 3650 # You can test SSL handshake running this script and trying to connect using wget: # $ wget -O /dev/null https://$HOST:$PORT/

探索号

@seeker_rc · Post #19936 · 08.05.2026 г., 02:25

开发了个简单的 ping-pong+监控的小软件 软件有三个功能: 1. 启动时会访问设置好的 webhook (目的:在系统启动成功或母机意外重启时给自己发一条通知,能及时知道) 2. 启动一个 ping-pong http 服务,默认端口 10101 (目的:可以让另外一台主机检测本机是否运行正常) 3. 可以监控一个或多个设定的 url (一个简单的定检测功能,可以监控给定的 url 是否正常运行,如果访问失败,会请求前面设定的 webhook ,并支持修改参数) github: <https://github.com/yafoo/ping-pong> 如果你有这方面需求可以试试。 ... via V2EX 分享创造 标签: #ping#pong#webhook ⚡️探索号频道 ⚡️探索者频道 ⚡️探索者交流群 ⚡️ Youtube 频道:科技探索者 每天推荐有趣内容,欢迎订阅、转发。

djangoproject

@djangoproject · Post #122 · 25.08.2016 г., 04:45

https://github.com/python-telegram-bot/python-telegram-bot/wiki/Webhooks#heroku On #Heroku using #webhook can be beneficial on the free-plan because it will automatically manage the downtime required. The reverse proxy is set up for you and an environment is created. From this environment you will have to extract the port the #bot is supposed to listen on. Heroku manages the #SSL on the #proxy side, so you don't have provide the certificate yourself.