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

Резултати

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

Пребарај: #texto

当前筛选 #texto清除筛选
BotsGram®

@botsgram_cu · Post #3743 · 31.03.2021 г., 13:57

¿Que puede hacer este bot? @QuotAfBot Crea pegatinas animadas con un texto que le envíes Idiomas: varios incluido español (Visto en @botsgram_cu) #stickers#texto

BotsGram®

@botsgram_cu · Post #4296 · 26.08.2021 г., 17:46

¿Que puede hacer este bot? @WebScrapperRoBot Con este bot puedes obtener todo el texto de un sitios web Idiomas: inglés (Visto en @botsgram_cu) #web#texto

Hashtags

BotsGram®

@botsgram_cu · Post #3093 · 27.10.2020 г., 02:57

¿Que puede hacer este bot? @TextChangerBot Un bot para convertir texto a varias fuentes. Perfecto para configurar perfiles en redes sociales, apodos para juegos y más. Idioma: ruso (Visto en @botsgram_cu) #texto#fuentes

BotsGram®

@botsgram_cu · Post #3061 · 11.10.2020 г., 05:40

¿Que puede hacer este bot? @COOLTEXTGENERATORBOT Bot para decorar y darle estilo al texto en muchas fuentes Idiomas: inglés (Visto en @botsgram_cu) #fuentes#texto

BotsGram®

@botsgram_cu · Post #4473 · 31.10.2021 г., 03:27

¿Que puede hacer este bot? @TypographicBot Este bot puede cambiar la tipografía de los mensajes que le envías Idiomas: inglés (Visto en @botsgram_cu) #texto#estilo

BotsGram®

@botsgram_cu · Post #4048 · 24.06.2021 г., 17:15

¿Que puede hacer este bot? @TheCarbonShBot Crea y comparte hermosas imágenes de su código fuente. Envíele un fragmento de código y le responderá con una bonita imagen de ese código. Idioma: inglés (soporta cualquier idioma en la conversión) (Visto en @botsgram_cu) #texto#fuente

BotsGram®

@botsgram_cu · Post #3946 · 27.05.2021 г., 15:19

¿Que puede hacer este bot? @BettergramBot Crea textos creativos con fuentes personalizadas. Idiomas: inglés (Visto en @botsgram_cu) #texto#fuente

BotsGram®

@botsgram_cu · Post #3738 · 30.03.2021 г., 18:54

¿Que puede hacer este bot? @MasquerBot Este bot utiliza un algoritmo de cifrado de última generación y manipulación de píxeles para enmascarar cualquier texto dentro de cualquier imagen dada. Idioma: inglés (Visto en @botsgram_cu) #edición#fotos#texto

BotsGram®

@botsgram_cu · Post #4002 · 10.06.2021 г., 13:19

¿Que puede hacer este bot? @bacakubot Con este bot podrás extraer texto de una imagen o foto y traducirlo a cualquier idioma Idiomas: inglés (Visto en @botsgram_cu) #texto#imágenes#traductor

BotsGram®

@botsgram_cu · Post #4903 · 06.09.2023 г., 13:44

¿Que puede hacer este bot? 🤖@IMG2TEXTBot 📎Este bot utiliza el reconocimiento óptico de caracteres (OCR) para detectar texto en imágenes. #Imagen#texto#IA ( Visto en: @BotsGram_Cu )

BotsGram®

@botsgram_cu · Post #4950 · 29.03.2024 г., 13:02

¿Qué puede hacer este bot? 🤖@Ai_Text2Speechbot Es una herramienta fácil de usar que transforma texto escrito en audio hablado. Utiliza algoritmos avanzados de síntesis de voz para generar un habla precisa y con un sonido natural con gran variedad de acentos, para que puedas disfrutar de una experiencia auditiva de alta calidad. Además, es fácil de usar: simplemente envíe un texto escrito al bot y generará un archivo de audio en segundos. Idiomas: Más de 50 idiomas #ia#tts#voz#texto (Visto en @BotsGram_Cu)

12
ПретходнаСтраница 1 од 2Следна