Python、Perl 垫底,C语言才是最环保的编程语言
<div style="color: black; text-align: left; margin-bottom: 10px;">
<div style="color: black; text-align: left; margin-bottom: 10px;"> <img src="https://p3-sign.toutiaoimg.com/tos-cn-i-tjoges91tu/SibV8eWA3BB2xx~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1723892545&x-signature=3ub0ADnQMCXojQ6yrI5ynifZodk%3D" style="width: 50%; margin-bottom: 20px;"><span style="color: black;"><span style="color: black;">作者 | </span><span style="color: black;">JEAN-LUC AUFRANC</span></span><span style="color: black;">
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">译者 | 弯月</p>
</span><span style="color: black;">出品 | CSDN(ID:CSDNnews)</span><span style="color: black;"><span style="color: black;">说到</span>编程语言,人们<span style="color: black;">第1</span>时间想到的无非是:哪个编程语言简单易学,<span style="color: black;">也</span>或是最挣钱等。<span style="color: black;">然则</span>编程语言功耗问题却被<span style="color: black;">非常多</span>人<span style="color: black;">忽略</span>。<span style="color: black;">那样</span><span style="color: black;">做为</span>程序员的<span style="color: black;">咱们</span><span style="color: black;">怎样</span><span style="color: black;">选取</span>编程语言,使其以低能耗高功效地工作呢?</span><span style="color: black;">2017年,葡萄牙大学的<span style="color: black;">科研</span>人员团队曾<span style="color: black;">发布</span>过一篇题为《<span style="color: black;">各样</span>编程语言的能耗》的论文,<span style="color: black;">她们</span>比较了各个编程语言(及其编译器/解释器)的能耗,为此<span style="color: black;">她们</span><span style="color: black;">科研</span>了 27 种知名编程语言的运行时、内存<span style="color: black;">运用</span><span style="color: black;">状况</span>以及能耗。最后,C <span style="color: black;">作为</span>了无可争议的赢家,其能耗最低,而 Python 和 Perl 则<span style="color: black;">处在</span>最末位。</span><span style="color: black;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-tjoges91tu/SplUXyRHJbUKMX~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1723892545&x-signature=Pij1KflqE9zBmKHMoVM8ao7XOyU%3D" style="width: 50%; margin-bottom: 20px;"></span>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">据说</span>,这项<span style="color: black;">科研</span>采用了多种<span style="color: black;">办法</span>论和多个基准测试。每种语言<span style="color: black;">运用</span>十个编程问题来进行调查,<span style="color: black;">帮忙</span><span style="color: black;">科研</span>人员<span style="color: black;">得到</span>更<span style="color: black;">拥有</span>可比性、<span style="color: black;">表率</span>性和广泛性的程序,以及编译/执行选项和编译器版本。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-tjoges91tu/SibV8iB7gfIVeO~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1723892545&x-signature=eM%2FebPlD3%2FZa4HHyZxOdjny%2Bhu0%3D" style="width: 50%; margin-bottom: 20px;"></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;"><span style="color: black;">C /C++能耗最低且最快</span></strong></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">尽管人们<span style="color: black;">广泛</span>认为程序运行速度更快时能源消耗会随之降低,但论文中<span style="color: black;">知道</span>指出“更快的语言并不总是最节能的”,强调这并不像 E(nergy) = T(ime) x P(ower) 的<span style="color: black;">理学</span>定律<span style="color: black;">那样</span>简单。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">例如</span>在<span style="color: black;">她们</span>的一项基准测试中,Chapel 程序的执行时间比用 Pascal 编写的等效程序少 55%——但 Pascal 程序<span style="color: black;">运用</span>的能量少 10%。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">在人们传统印象中,编译语言“<span style="color: black;">常常</span>”是最节能、运行速度最快的。<span style="color: black;"><span style="color: black;">首要</span><span style="color: black;">咱们</span>来看一看编译语言在二叉树测试上的结果。</span></span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-tjoges91tu/SplUY0j9WrdXFk~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1723892545&x-signature=hxfB3aPW0znh7FSXL0h5KcsNskQ%3D" style="width: 50%; margin-bottom: 20px;"></span></p><span style="color: black;">不出意料,这项<span style="color: black;">科研</span>得出的结论为:编译语言是最快和最节能的语言。C 和 C++ 语言是能耗最低且最快的语言。Go 是编译语言中表现最差的语言,<span style="color: black;">乃至</span>比依赖虚拟机的 Java 或 Erlang 等还要糟糕,<span style="color: black;">最少</span>在二叉树的测试中是<span style="color: black;">这般</span>。</span>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-tjoges91tu/SibV8qW8mqM9VB~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1723892545&x-signature=I7CJGCxEOQ%2FhGs6uMA%2BrdhNHGb8%3D" style="width: 50%; margin-bottom: 20px;"></p><strong style="color: blue;"><span style="color: black;">Perl、Lua 和 Python能耗高</span></strong><span style="color: black;">下面看一下解释型语言在速度与能耗方面的表现,由测试可知解释型语言才是能耗最高的语言,<span style="color: black;">例如</span> Perl、Lua 和 Python。</span><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-tjoges91tu/SplUYPeHtKbLho~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1723892545&x-signature=%2FReLERCXB5GcBlp7f6BpkpXHnQc%3D" style="width: 50%; margin-bottom: 20px;">
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">而5 种最慢的语言<span style="color: black;">亦</span>是解释型语言,如:Lua、Python、Perl、Ruby 和 Type。但在<span style="color: black;">运用</span>正则表达式操作字符串时,5 种最节能的语言中有三种解释型语言,分别是 TypeScript、JavaScript 和 PHP。</span></p><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-tjoges91tu/SplUYQB4QWerUj~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1723892545&x-signature=w7p9rjKP7lai48RL5LpSSgBTCY8%3D" style="width: 50%; margin-bottom: 20px;"><span style="color: black;">请<span style="color: black;">重视</span>,所有测试都是在如下环境运行:Intel Core i5-4460 Haswell CPU @ 3.20GHz,16GBRAM,Ubuntu Server 16.10 操作系统和Linux 4.8.0-22。<span style="color: black;">思虑</span>到如今 MicroPyhon <span style="color: black;">能够</span>在<span style="color: black;">各样</span>微<span style="color: black;">掌控</span>器上运行,猜它在体积更小的设备上的表现可能不会<span style="color: black;">那样</span>糟糕。</span><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-tjoges91tu/SplUYQgDgc9dQK~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1723892545&x-signature=YdLLD7tjAIL7phLvgwrVCk8Gcq8%3D" style="width: 50%; margin-bottom: 20px;"><span style="color: black;"><span style="color: black;">另外</span>,这项<span style="color: black;">科研</span>还<span style="color: black;">按照</span>时间、内存和能耗参数的<span style="color: black;">区别</span><span style="color: black;">目的</span>组合,对每种语言进行了排名,而在这些指标中 C 语言始终名列前茅。这与人们<span style="color: black;">很久</span><span style="color: black;">败兴</span>的认知相同,<span style="color: black;">倘若</span>你想优化程序,<span style="color: black;">加强</span>续航时间,降低功耗,则 C 语言绝对是最佳<span style="color: black;">选取</span>、汇编语言、SIMD 指令或加速器的自定义指令优化某些例程。</span><span style="color: black;">参考链接:</span>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">https://www.cnx-software.com/2021/11/18/save-the-planet-program-in-c-avoid-python-perl/</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-tjoges91tu/SibQdFG3L4dsMd~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1723892545&x-signature=NLvuGeFTXcfeVUPE3xRBQUJHbwU%3D" style="width: 50%; margin-bottom: 20px;"></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">为助力云原生<span style="color: black;">研发</span>者更好迎接即将到来的“黄金十年”,CSDN <span style="color: black;">尤其</span>发起《<strong style="color: blue;">2021中国云原生<span style="color: black;">研发</span>者调查报告</strong>》,<span style="color: black;">围绕“云原生<span style="color: black;">研发</span>者画像、人才和技术分布版图、一线<span style="color: black;">研发</span>者的技术实践、场景与应用分析、云原生的技术<span style="color: black;">将来</span>”等五大方面进行深度调查和解析。</span></span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">这次</span>问卷调查共 10 个问题,可能占用您 3-5 分钟时间,感谢您的倾力支持。</span></p>
</div>
</div>
楼主果然英明!不得不赞美你一下! 外链发布社区 http://www.fok120.com/ 软文发布论坛开幕式圆满成功。 http://www.fok120.com 论坛的成果是显著的,但我们不能因为成绩而沾沾自喜。 你的见解真是独到,让我受益良多。
页:
[1]