热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

编程语言的性能多久经常成为一个重要问题?-Howoftenistheperformanceofaprogramminglanguageasignificantissue?

ItseemsthatIoftenhearpeoplecriticizecertainprogramminglanguagesbecausetheyhavepoorpe

It seems that I often hear people criticize certain programming languages because they "have poor performance", or because some other language is "faster" in general (not necessarily for a specific application). However, my experience and education have taught me that anytime you have a performance problem, at least one of the following is probably happening:

似乎我经常听到人们批评某些编程语言,因为他们“表现不佳”,或者因为某些其他语言一般“更快”(不一定针对特定应用)。但是,我的经验和教育告诉我,无论何时遇到性能问题,至少可能发生以下一种情况:

  1. The bottleneck isn't in the CPU, it's in some other device, such as the network or the hard drive.
  2. 瓶颈不在CPU中,而在某些其他设备中,例如网络或硬盘驱动器。

  3. The poor performance is caused by your algorithms, not by the language you're using.
  4. 性能不佳是由您的算法引起的,而不是由您使用的语言引起的。

My general impression is that the speed of a programming language itself is all but irrelevant in the vast majority of cases, with exceptions for serious data processing problems. Even in those cases, I believe you could use a hybrid approach and use a lower-level language only for the CPU-intensive pieces so that you wouldn't lose the benefits of the more abstract language altogether.

我的总体印象是,编程语言本身的速度在绝大多数情况下都是无关紧要的,严重的数据处理问题除外。即使在这些情况下,我相信你可以使用混合方法,并且只为CPU密集型部分使用低级语言,这样你就不会完全失去更抽象语言的好处。

Do you agree? Is programming language speed insignificant most of the time, or do the critics have a right to point out language performance issues?

你同意吗?编程语言的速度在大多数时候都是微不足道的,还是批评者有权指出语言表现问题?

I hope this question isn't too subjective, but it seems to me that there should be a relatively objective answer to this.

我希望这个问题不是太主观,但在我看来应该有一个相对客观的答案。

5 个解决方案

#1


Performance can be a serious concern in libraries, operating systems, and the like. However, I believe that upwards of 90% of the time raw performance is irrelevant.

在图书馆,操作系统等中,性能可能是一个严重的问题。但是,我认为超过90%的原始性能是无关紧要的。

What is more important in many cases is TIMING. Any garbage collected language is going to have some unpredictability in this regard, which makes them unsuited to embedded and realtime design spaces.

在许多情况下更重要的是TIMING。任何垃圾收集语言在这方面都会有一些不可预测性,这使得它们不适合嵌入式和实时设计空间。

The overlap of GC'd and "slow" languages is considerable, and so you may see a language discounted for speed reasons when the real problem is inconsistent timing.

GC'd和“慢”语言的重叠是相当可观的,因此当真正的问题是不一致的时间时,您可能会看到由于速度原因而打折的语言。

There are some allocation/threading/etc. schemes that allow for garbage collection while also guaranteeing the runtime of parts of the system, such as Realtime Java, though I haven't personally seen it in use anywhere.

有一些分配/线程/等。允许垃圾收集的方案,同时也保证系统部分的运行时,例如Realtime Java,尽管我没有亲眼看到它在任何地方使用过。

Short answer: most of the time the speed of the language is irrelevant (within reason), language choices are made based on familiarity and available libraries.

简答:大多数时候语言的速度是无关紧要的(在合理范围内),语言选择是基于熟悉程度和可用的库。

#2


Amazingly, the performance of a system is a combination of the programming language, the system it's executing on, the operations that system is performing and the external resources (network, disk, slow line printers, etc.) that it relies upon.

令人惊讶的是,系统的性能是编程语言,正在执行的系统,系统正在执行的操作以及它依赖的外部资源(网络,磁盘,慢速打印机等)的组合。

If your system is slow, rather than guessing, test it.

如果您的系统很慢,而不是猜测,请测试它。

If there is any "Rule" in computing, it's "Test your assumptions". Everything else is gross guideline.

如果计算中有任何“规则”,那就是“测试你的假设”。其他一切都是严格的准则。

#3


This is impossible to answer so broadly. It's like asking if big engines are a waste in cars. Well, for some people, yes. For others, not at all. And all sorts in between.

这不可能如此广泛地回答。这就像问大型发动机是否是汽车浪费一样。嗯,对某些人来说,是的。对于其他人,根本不是。介于两者之间。

There are a myriad of factors that come in to play. What is your target environment? End-user deployment or servers? Let's suppose we're talking about web development and coding for a server. RoR is well-known to be (relatively) slow. .NET is pretty fast by comparison. But RoR also has RAD qualities that .NET can't compete with.

有许多因素可以发挥作用。你的目标环境是什么?最终用户部署还是服务器?我们假设我们正在讨论服务器的Web开发和编码。众所周知,RoR(相对)缓慢。相比之下,.NET相当快。但是RoR也具有.NET无法与之竞争的RAD特性。

  • Is getting your app up-and-running yesterday more of a priority than scalability?
  • 昨天让您的应用程序正常运行比可扩展性更重要吗?

  • Does your business model live or die on the milliseconds you serve a page, or the time you went to market?
  • 您的商业模式是在您服务页面的毫秒数或您上市时间的情况下生存还是死亡?

  • Does your TCO and application architecture support scaling out or scaling up? Do you even expect to need to scale up?
  • 您的TCO和应用程序架构是否支持扩展或扩展?你甚至希望扩大规模吗?

Those are just a tiny handful of the questions an architect has to answer when making platform/language decisions. Does speed matter? Sometimes. If I am planning to write a LoB service that will eventually need to scale to thousands of transactions per second, and it will be deployed in an enterprise environment, I will probably go with .NET. If I have an idea for a Web 2.0 business like selling Twitter teeshirts, I need to capitalize on that idea yesterday and I can know I probably won't get slammed with enough business to bring the site down before preparing for it.

这些只是建筑师在制定平台/语言决策时必须回答的极少数问题。速度重要吗?有时。如果我打算编写一个最终需要扩展到每秒数千个事务的LoB服务,并且它将部署在企业环境中,我可能会使用.NET。如果我对像销售Twitter teeshirts这样的Web 2.0业务有所了解,我需要在昨天利用这个想法,我知道在准备之前我可能不会受到足够的业务打击以使网站崩溃。

This is honestly over-simplifying a very complex issue, but hopefully illustrated the point that it's impossible to simply "say" whether it matters or not.

这实际上过分简化了一个非常复杂的问题,但希望说明一点就是说“说”是否重要是不可能的。

#4


I think it's a good question. To answer it requires having a general framework for thinking about performance, so let me try to provide one. (Some of this is going to sound really obvious, but bear with me.)

我认为这是一个很好的问题。要回答它需要一个考虑性能的一般框架,所以让我试着提供一个。 (其中一些听起来很明显,但请耐心等待。)

To keep things simple, let's just consider the simple case of applications that have a specific job to do, and that start, and then finish, and what you care about is wall-clock time. Let's assume a standard CPU cycle rate, and a mono-processor.

为了简单起见,我们只考虑具有特定工作的应用程序的简单情况,然后开始,然后完成,您关心的是挂钟时间。我们假设一个标准的CPU循环速率和一个单处理器。

The time duration consists of a stream of time-slices (nanoseconds, say). To do that job, there is a minimum amount of time required, and it is usually greater than zero. There is no maximum amount of time required. If a program spends longer than the minimum number of nanoseconds, then some of those nanoseconds are being spent, strictly speaking, unnecessarily (i.e. for poor reasons).

持续时间由时间片流组成(例如纳秒)。要做这项工作,所需的时间最短,通常大于零。没有最长的时间。如果程序花费的时间超过最小纳秒数,则严格来说,这些纳秒中的一些是不必要的(即由于不良原因)。

So, to optimize a program's execution time, it is necessary to find the nanoseconds it is spending that do not have to be spent (i.e. that do not have good reasons) and remove them.

因此,为了优化程序的执行时间,有必要找到不必花费的纳秒(即没有充分理由)并删除它们。

One way to do this is to, if possible, step through the program and keep track at each step of why it is doing that step. If the reason is not good, there is an opportunity for removing steps.

实现此目的的一种方法是,如果可能的话,逐步完成程序并跟踪每个步骤,了解它为什么要执行该步骤。如果原因不好,则有机会删除步骤。

Another way to do this is to select nanoseconds at random from the program's execution, and inquire their reasons. For example, the program counter can tell you what the program is doing, but the call stack can tell you why. In order for the nanosecond to be spent for a good reason, every call instruction on the call stack has to have a good reason. If any instruction on the call stack does not have a good reason, then there is an opportunity to optimize. In fact, the amount of time that instruction is on the call stack is the amount of time that would be saved by its removal.

另一种方法是从程序执行中随机选择纳秒,并查询其原因。例如,程序计数器可以告诉您程序正在做什么,但调用堆栈可以告诉您原因。为了有充分理由花费纳秒,调用堆栈上的每个调用指令都有充分的理由。如果调用堆栈上的任何指令没有充分的理由,那么就有机会进行优化。事实上,指令在调用堆栈上的时间量是删除它所节省的时间。

In some kinds of software that are highly asynchronous, message-driven, or interpreted, the call stack may not provide enough information. In that case, to answer why a given nanosecond is being spent may be more difficult. It may require examining more state information than just the call stack. For example, in an interpreter, the stack of the program being interpreted may also need to be examined. However, often the hardware call stack does provide sufficient information, so it is a useful thing to examine.

在某些高度异步,消息驱动或解释的软件中,调用堆栈可能无法提供足够的信息。在这种情况下,回答为什么给定纳秒被花费可能会更困难。它可能需要检查比调用堆栈更多的状态信息。例如,在解释器中,还可能需要检查被解释的程序的堆栈。但是,通常硬件调用堆栈确实提供了足够的信息,因此检查它是一件有用的事情。

Now, to try to answer your question.

现在,试着回答你的问题。

There is such a thing as a "hot spot". This is a small set of addresses that are often at the bottom of the call stack. Nanoseconds spent in that code may or may not have good reasons.

有一个“热点”之类的东西。这是一小组地址,通常位于调用堆栈的底部。在该代码中花费的纳秒可能有也可能没有充分的理由。

There is such a thing as a "performance problem". This is an instruction that often accounts for why nanoseconds are being spent, but that does not have a good reason. Such an instruction may be in a hot spot. It may also be a subroutine call instruction. (It cannot be both.) It may be an instruction to send a message to be processed later, that does not have a good reason for being spent. To optimize software, such instructions (not functions) are what are being looked for.

存在“性能问题”这样的问题。这是一个经常说明为什么要花费纳秒的指令,但这没有充分的理由。这样的指令可能处于热点。它也可以是子程序调用指令。 (它不能同时存在。)它可能是一个发送消息以便稍后处理的指令,这种指令没有充分的理由被用掉。为了优化软件,正在寻找这些指令(而不是功能)。

Languages, loosely speaking, are either compiled into machine language or interpreted. Interpreted languages are usually 1 or 2 orders of magnitude slower than compiled, because they are constantly re-determining what they need to do. However, roughly speaking, this is only a performance problem if it occurs in a hot spot. If a program spends all its time calling compiled library functions, or waiting for I/O completions, then its speed of execution probably doesn't matter, because most of the nanoseconds are being spent for other reasons.

松散地说,语言要么被编译成机器语言,要么被解释。解释语言通常比编译语言慢1或2个数量级,因为它们不断地重新确定他们需要做什么。但是,粗略地说,如果它出现在热点中,这只是一个性能问题。如果程序花费所有时间来调用编译库函数,或者等待I / O完成,那么它的执行速度可能无关紧要,因为大多数纳秒都是由于其他原因而花费的。

Now, certainly, any language or program can in principle be highly non-optimal, but in terms of compilers, for hotspot code, they are mostly pretty good, give or take maybe 30%. If there is a background process involved, like garbage collection, that adds an overhead, but it depends on the rate at which the program generates garbage.

现在,当然,任何语言或程序原则上都可能是高度非最佳的,但就编译器而言,对于热点代码而言,它们大多数都非常好,可以给出或者占用30%。如果涉及后台进程,如垃圾收集,则会增加开销,但这取决于程序生成垃圾的速率。

So to sum up, the speed of a language matters in hotspot code, but not much elsewhere. When a program has been optimized by removal of all other performance problems, and if the hotspot code is actually seen by the compiler/interpreter, then speed of language matters.

总而言之,语言的速度在热点代码中很重要,但在其他地方并不多。通过删除所有其他性能问题来优化程序,并且如果编译器/解释器实际看到热点代码,则语言速度很重要。

#5


Your question is framed very broadly, so I'll try to give a somewhat narrower answer:

你的问题框架非常广泛,所以我会尝试给出一个稍微狭窄的答案:

  • Unless there is some good reason not to do so, the language for a project should always be chosen from among those languages that will help the project team be productive and produce reliable software that can easily be adapted for future needs. The tradeoffs generally favor high-level languages with automatic memory management.

    除非有充分的理由不这样做,否则应始终从能够帮助项目团队提高工作效率并生成可以轻松适应未来需求的可靠软件的语言中选择项目的语言。权衡通常倾向于使用自动内存管理的高级语言。

    N.B. There are plenty of good reasons to make other choices, such as compatibility with current products and libraries.

    注:做出其他选择有很多充分的理由,例如与当前产品和库的兼容性。

  • It sometimes happens that when a program is too slow, the quickest and easiest way to speed it up is to rewrite the program (or a critical part) in a new language. This happens most often when the implementation language is interpreted and the new language is compiled.

    有时候,当程序太慢时,加快速度的最快捷最简单的方法就是用新语言重写程序(或关键部分)。这种情况最常发生在解释实现语言并编译新语言时。

    Example: I got about a 4x speedup out of the OSBF-Lua spam filter by rewriting the lexical analysis of the mail headers. By rewriting from Lua to C I not only went from interpreted to compiled but was able to eliminate an array-bounds check for every input character.

    示例:通过重写邮件头的词法分析,我从OSBF-Lua垃圾邮件过滤器中获得了大约4倍的加速。通过从Lua重写为C,我不仅从解释到编译,而且能够消除每个输入字符的数组边界检查。

To answer your question as stated, it is not very often that language performance per se is an issue.

要回答上述问题,语言表现本身并不常见。


推荐阅读
  • 本文深入探讨了 MXOTDLL.dll 在 C# 环境中的应用与优化策略。针对近期公司从某生物技术供应商采购的指纹识别设备,该设备提供的 DLL 文件是用 C 语言编写的。为了更好地集成到现有的 C# 系统中,我们对原生的 C 语言 DLL 进行了封装,并利用 C# 的互操作性功能实现了高效调用。此外,文章还详细分析了在实际应用中可能遇到的性能瓶颈,并提出了一系列优化措施,以确保系统的稳定性和高效运行。 ... [详细]
  • POJ 2482 星空中的星星:利用线段树与扫描线算法解决
    在《POJ 2482 星空中的星星》问题中,通过运用线段树和扫描线算法,可以高效地解决星星在窗口内的计数问题。该方法不仅能够快速处理大规模数据,还能确保时间复杂度的最优性,适用于各种复杂的星空模拟场景。 ... [详细]
  • 在处理 XML 数据时,如果需要解析 `` 标签的内容,可以采用 Pull 解析方法。Pull 解析是一种高效的 XML 解析方式,适用于流式数据处理。具体实现中,可以通过 Java 的 `XmlPullParser` 或其他类似的库来逐步读取和解析 XML 文档中的 `` 元素。这样不仅能够提高解析效率,还能减少内存占用。本文将详细介绍如何使用 Pull 解析方法来提取 `` 标签的内容,并提供一个示例代码,帮助开发者快速解决问题。 ... [详细]
  • 分享一款基于Java开发的经典贪吃蛇游戏实现
    本文介绍了一款使用Java语言开发的经典贪吃蛇游戏的实现。游戏主要由两个核心类组成:`GameFrame` 和 `GamePanel`。`GameFrame` 类负责设置游戏窗口的标题、关闭按钮以及是否允许调整窗口大小,并初始化数据模型以支持绘制操作。`GamePanel` 类则负责管理游戏中的蛇和苹果的逻辑与渲染,确保游戏的流畅运行和良好的用户体验。 ... [详细]
  • 本指南从零开始介绍Scala编程语言的基础知识,重点讲解了Scala解释器REPL(读取-求值-打印-循环)的使用方法。REPL是Scala开发中的重要工具,能够帮助初学者快速理解和实践Scala的基本语法和特性。通过详细的示例和练习,读者将能够熟练掌握Scala的基础概念和编程技巧。 ... [详细]
  • 本文探讨了 Kafka 集群的高效部署与优化策略。首先介绍了 Kafka 的下载与安装步骤,包括从官方网站获取最新版本的压缩包并进行解压。随后详细讨论了集群配置的最佳实践,涵盖节点选择、网络优化和性能调优等方面,旨在提升系统的稳定性和处理能力。此外,还提供了常见的故障排查方法和监控方案,帮助运维人员更好地管理和维护 Kafka 集群。 ... [详细]
  • 本文探讨了 Java 中 Pair 类的历史与现状。虽然 Java 标准库中没有内置的 Pair 类,但社区和第三方库提供了多种实现方式,如 Apache Commons 的 Pair 类和 JavaFX 的 javafx.util.Pair 类。这些实现为需要处理成对数据的开发者提供了便利。此外,文章还讨论了为何标准库未包含 Pair 类的原因,以及在现代 Java 开发中使用 Pair 类的最佳实践。 ... [详细]
  • 本文详细探讨了Zebra路由软件中的线程机制及其实际应用。通过对Zebra线程模型的深入分析,揭示了其在高效处理网络路由任务中的关键作用。文章还介绍了线程同步与通信机制,以及如何通过优化线程管理提升系统性能。此外,结合具体应用场景,展示了Zebra线程机制在复杂网络环境下的优势和灵活性。 ... [详细]
  • 掌握PHP编程必备知识与技巧——全面教程在当今的PHP开发中,了解并运用最新的技术和最佳实践至关重要。本教程将详细介绍PHP编程的核心知识与实用技巧。首先,确保你正在使用PHP 5.3或更高版本,最好是最新版本,以充分利用其性能优化和新特性。此外,我们还将探讨代码结构、安全性和性能优化等方面的内容,帮助你成为一名更高效的PHP开发者。 ... [详细]
  • RxJava 中 Observable.singleElement() 方法详解与实例代码分析 ... [详细]
  • 如何使用 net.sf.extjwnl.data.Word 类及其代码示例详解 ... [详细]
  • Python多线程编程技巧与实战应用详解 ... [详细]
  • 出库管理 | 零件设计中的状态模式学习心得与应用分析
    出库管理 | 零件设计中的状态模式学习心得与应用分析 ... [详细]
  • 开发日志:201521044091 《Java编程基础》第11周学习心得与总结
    开发日志:201521044091 《Java编程基础》第11周学习心得与总结 ... [详细]
  • 分布式开源任务调度框架 TBSchedule 深度解析与应用实践
    本文深入解析了分布式开源任务调度框架 TBSchedule 的核心原理与应用场景,并通过实际案例详细介绍了其部署与使用方法。首先,从源码下载开始,详细阐述了 TBSchedule 的安装步骤和配置要点。接着,探讨了该框架在大规模分布式环境中的性能优化策略,以及如何通过灵活的任务调度机制提升系统效率。最后,结合具体实例,展示了 TBSchedule 在实际项目中的应用效果,为开发者提供了宝贵的实践经验。 ... [详细]
author-avatar
郭倩尔偏执起来不是人_
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有