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

Резултати

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

Пребарај: #aiconvention

当前筛选 #aiconvention清除筛选
AI & Law

@ai_and_law · Post #406 · 27.09.2024 г., 07:04

New Article Highlights Europe's Dual Approach to AI: Human Rights vs. Market Regulation A recent article by Virginia Dignum, Director of the AI Policy Lab at Umeå University, sheds light on the evolving landscape of AI governance in Europe. The piece compares two pivotal frameworks: the newly introduced Council of Europe's Framework Convention on AI, Human Rights, Democracy, and the Rule of Law, and the EU's AI Act. The Council of Europe convention, open for signatures as of September 2024, emphasizes the protection of human rights, transparency, and accountability in all AI sectors. In contrast, the AI Act takes a more business-focused approach, offering clear regulatory guidelines with a risk-based model, particularly for high-impact sectors like healthcare. While the AI Act fosters innovation and compliance, the Council of Europe's broader focus aims to ensure AI upholds democratic values and the rule of law, signaling Europe's comprehensive strategy for ethical AI development. #AIRegulation#AIConvention#AIAct#EthicalAI#Transparency#Innovation

AI & Law

@ai_and_law · Post #46 · 04.07.2023 г., 07:04

UK: Report calls for ethical AI future and robust governance The All-Party Parliamentary Group on Data Analytics in the UK has released a report titled "An Ethical AI Future: Guardrails & Catalysts to make Artificial Intelligence a Force for Good." The report aims to explore how an effective governance and regulatory framework can maximize the benefits of AI while addressing existing risks such as deep fakes and preparing for potential future risks. The report puts forth several key recommendations to shape the future of AI governance: 1️⃣ Strengthen international engagement. 2️⃣ Champion AI ethics convention. 3️⃣ Embedding 'Do No Harm' objective. 4️⃣ Establish independent regulatory authority. #EthicalAI#AIRegulation#Governance#AIConvention#Accountability