什么是“开销”?

发布于 2024-09-02 04:41:01 字数 56 浏览 3 评论 0原文

我是一名计算机科学专业的学生,​​当谈到程序和排序时,我经常听到“开销”这个词。这究竟意味着什么?

I am a student in Computer Science and I am hearing the word "overhead" a lot when it comes to programs and sorts. What does this mean exactly?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(13

演多会厌 2024-09-09 04:41:01

这是建立运营所需的资源。这看起来似乎无关,但却是必要的。

就像当你需要去某个地方时,你可能需要一辆车。但是,让汽车在街上行驶会花费很多费用,因此您可能需要步行。然而,如果你要穿越这个国家,那么这些开销是值得的。

在计算机科学中,有时我们使用汽车在街上行走,因为我们没有更好的方法,或者不值得我们花时间“学习如何走路”。

It's the resources required to set up an operation. It might seem unrelated, but necessary.

It's like when you need to go somewhere, you might need a car. But, it would be a lot of overhead to get a car to drive down the street, so you might want to walk. However, the overhead would be worth it if you were going across the country.

In computer science, sometimes we use cars to go down the street because we don't have a better way, or it's not worth our time to "learn how to walk".

何处潇湘 2024-09-09 04:41:01

该词的含义可能因上下文而有很大差异。一般来说,所使用的资源(最常见的是内存和 CPU 时间)不会直接影响预期结果,但却是所使用的技术或方法所需要的。示例:

  • 协议开销:以太网帧、IP 数据包和 TCP 段都有标头,TCP 连接需要握手数据包。因此,您无法将硬件能够提供的全部带宽用于实际数据。您可以通过使用较大的数据包大小来减少开销,并且 UDP 具有较小的标头并且无需握手。
  • 数据结构内存开销:链表中包含的每个元素至少需要一个指针。如果元素的大小与指针相同,则意味着 50% 的内存开销,而数组可能有 0% 的开销。
  • 方法调用开销:一个设计良好的程序被分解为许多简短的方法。但每个方法调用都需要设置堆栈帧、复制参数和返回地址。与在单个整体函数中完成所有操作的程序相比,这表示 CPU 开销。当然,增加的可维护性使其非常值得,但在某些情况下,过多的方法调用可能会对性能产生重大影响。

The meaning of the word can differ a lot with context. In general, it's resources (most often memory and CPU time) that are used, which do not contribute directly to the intended result, but are required by the technology or method that is being used. Examples:

  • Protocol overhead: Ethernet frames, IP packets and TCP segments all have headers, TCP connections require handshake packets. Thus, you cannot use the entire bandwidth the hardware is capable of for your actual data. You can reduce the overhead by using larger packet sizes and UDP has a smaller header and no handshake.
  • Data structure memory overhead: A linked list requires at least one pointer for each element it contains. If the elements are the same size as a pointer, this means a 50% memory overhead, whereas an array can potentially have 0% overhead.
  • Method call overhead: A well-designed program is broken down into lots of short methods. But each method call requires setting up a stack frame, copying parameters and a return address. This represents CPU overhead compared to a program that does everything in a single monolithic function. Of course, the added maintainability makes it very much worth it, but in some cases, excessive method calls can have a significant performance impact.
揪着可爱 2024-09-09 04:41:01

你累了,无法再做任何工作。你吃食物。寻找食物、获取食物和实际吃掉食物所花费的能量会消耗能量,而且是开销!

开销是为了完成任务而浪费的东西。目标是使开销非常非常小。

在计算机科学中,假设您想打印一个数字,这就是您的任务。但是存储数字、设置显示来打印它、调用例程来打印它、然后从变量访问数字都是开销。

You're tired and cant do any more work. You eat food. The energy spent looking for food, getting it and actually eating it consumes energy and is overhead!

Overhead is something wasted in order to accomplish a task. The goal is to make overhead very very small.

In computer science lets say you want to print a number, thats your task. But storing the number, the setting up the display to print it and calling routines to print it, then accessing the number from variable are all overhead.

再见回来 2024-09-09 04:41:01

维基百科涵盖了我们

在计算机科学中,开销
一般认为是任意组合
过度或间接计算
时间、内存、带宽或其他
达到目标所需的资源
一个特定的目标。这是一个特殊的
工程开销案例。

Wikipedia has us covered:

In computer science, overhead is
generally considered any combination
of excess or indirect computation
time, memory, bandwidth, or other
resources that are required to attain
a particular goal. It is a special
case of engineering overhead.

往事风中埋 2024-09-09 04:41:01

开销通常是指不同编程算法占用的额外资源(内存、处理器、时间等)的数量。

例如,插入平衡二叉树的开销可能比插入简单链表的开销大得多(插入将花费更长的时间,使用更多的处理能力来平衡树,这会导致更长的感知操作时间)用户)。

Overhead typically reffers to the amount of extra resources (memory, processor, time, etc.) that different programming algorithms take.

For example, the overhead of inserting into a balanced Binary Tree could be much larger than the same insert into a simple Linked List (the insert will take longer, use more processing power to balance the Tree, which results in a longer percieved operation time by the user).

情感失落者 2024-09-09 04:41:01

对于程序员来说,开销是指当代码在给定平台上的给定输入数据集上运行时所消耗的系统资源。通常该术语用于比较不同的实现或可能的实现。

例如,我们可能会说,一种特定的方法可能会产生相当大的 CPU 开销,而另一种方法可能会产生更多的内存开销,而另一种方法可能会加重网络开销(例如,并且需要外部依赖性)。

让我们举一个具体的例子:计算一组数字的平均值(算术平均值)。

显而易见的方法是循环输入,保留运行总计和计数。当遇到最后一个数字时(由“文件结束”EOF 或某些哨兵值或某些 GUI 按钮等发出信号),我们只需将总数除以输入数即可。

这种方法几乎不会产生 CPU、内存或其他资源的开销。 (这是一项微不足道的任务)。

另一种可能的方法是将输入“slurp”到列表中。迭代列表以计算总和,然后将其除以列表中有效项目的数量。

相比之下,这种方法可能会产生任意数量的内存开销。

在一个特别糟糕的实现中,我们可能会使用递归但没有尾部消除来执行求和运算。现在,除了列表的内存开销之外,我们还引入了堆栈开销(这是一种不同类型的内存,通常是比其他形式的内存更有限的资源)。

另一种(可以说更荒谬)的方法是将所有输入发布到 RDBMS 中的某个 SQL 表中。然后只需对该表的该列调用 SQL SUM 函数即可。这会将我们的本地内存开销转移到其他服务器,并产生网络开销和对我们执行的外部依赖性。 (请注意,远程服务器可能有也可能没有与此任务相关的任何特定内存开销——例如,它可能会立即将所有值推送到存储中)。

假设我们可能会考虑在某种集群上实现(可能使数万亿值的平均值变得可行)。在这种情况下,任何必要的值编码和分配(将它们映射到节点)以及结果的收集/整理(减少)都将计为开销。

我们还可以讨论程序员自己的代码之外的因素所产生的开销。例如,为 32 位或 64 位处理器编译某些代码可能需要比旧的 8 位或 16 位架构更大的开销。这可能涉及较大的内存开销(对齐问题)或 CPU 开销(CPU 被迫调整位顺序或使用非对齐指令等)或两者兼而有之。

请注意,代码及其库等占用的磁盘空间通常不称为“开销”,而是称为“占用空间”。此外,程序消耗的基本内存(不考虑它正在处理的任何数据集)也称为其“占用空间”。

For a programmer overhead refers to those system resources which are consumed by your code when it's running on a giving platform on a given set of input data. Usually the term is used in the context of comparing different implementations or possible implementations.

For example we might say that a particular approach might incur considerable CPU overhead while another might incur more memory overhead and yet another might weighted to network overhead (and entail an external dependency, for example).

Let's give a specific example: Compute the average (arithmetic mean) of a set of numbers.

The obvious approach is to loop over the inputs, keeping a running total and a count. When the last number is encountered (signaled by "end of file" EOF, or some sentinel value, or some GUI buttom, whatever) then we simply divide the total by the number of inputs and we're done.

This approach incurs almost no overhead in terms of CPU, memory or other resources. (It's a trivial task).

Another possible approach is to "slurp" the input into a list. iterate over the list to calculate the sum, then divide that by the number of valid items from the list.

By comparison this approach might incur arbitrary amounts of memory overhead.

In a particular bad implementation we might perform the sum operation using recursion but without tail-elimination. Now, in addition to the memory overhead for our list we're also introducing stack overhead (which is a different sort of memory and is often a more limited resource than other forms of memory).

Yet another (arguably more absurd) approach would be to post all of the inputs to some SQL table in an RDBMS. Then simply calling the SQL SUM function on that column of that table. This shifts our local memory overhead to some other server, and incurs network overhead and external dependencies on our execution. (Note that the remote server may or may not have any particular memory overhead associated with this task --- it might shove all the values immediately out to storage, for example).

Hypothetically we might consider an implementation over some sort of cluster (possibly to make the averaging of trillions of values feasible). In this case any necessary encoding and distribution of the values (mapping them out to the nodes) and the collection/collation of the results (reduction) would count as overhead.

We can also talk about the overhead incurred by factors beyond the programmer's own code. For example compilation of some code for 32 or 64 bit processors might entail greater overhead than one would see for an old 8-bit or 16-bit architecture. This might involve larger memory overhead (alignment issues) or CPU overhead (where the CPU is forced to adjust bit ordering or used non-aligned instructions, etc) or both.

Note that the disk space taken up by your code and it's libraries, etc. is not usually referred to as "overhead" but rather is called "footprint." Also the base memory your program consumes (without regard to any data set that it's processing) is called its "footprint" as well.

靖瑶 2024-09-09 04:41:01

开销就是程序执行过程中消耗的更多时间。例子 ;当我们调用一个函数并且它的控制权被传递到它定义的地方然后执行它的主体时,这意味着我们让我们的CPU运行一个很长的过程(首先将控制权传递到内存中的其他地方,然后在那里执行,然后将控件传递回之前的位置),因此需要大量的执行时间,因此会产生开销。我们的目标是通过在函数定义和调用时使用内联来减少这种开销,它会在函数调用时复制函数的内容,因此我们不会将控制权传递到其他位置,而是在一行中继续我们的程序,因此内联。

Overhead is simply the more time consumption in program execution. Example ; when we call a function and its control is passed where it is defined and then its body is executed, this means that we make our CPU to run through a long process( first passing the control to other place in memory and then executing there and then passing the control back to the former position) , consequently it takes alot performance time, hence Overhead. Our goals are to reduce this overhead by using the inline during function definition and calling time, which copies the content of the function at the function call hence we dont pass the control to some other location, but continue our program in a line, hence inline.

打小就很酷 2024-09-09 04:41:01

你可以使用字典。定义是一样的。但为了节省您的时间,间接费用是完成生产性工作所需的工作。例如,算法运行并完成有用的工作,但需要内存来完成其工作。这种内存分配需要时间,并且与正在完成的工作没有直接关系,因此是开销。

You could use a dictionary. The definition is the same. But to save you time, Overhead is work required to do the productive work. For instance, an algorithm runs and does useful work, but requires memory to do its work. This memory allocation takes time, and is not directly related to the work being done, therefore is overhead.

夏见 2024-09-09 04:41:01

您可以查看维基百科。但主要是在使用更多操作或资源时。就像如果您熟悉 .NET 一样,您可以拥有值类型和引用类型。引用类型具有内存开销,因为它们比值类型需要更多的内存。

You can check Wikipedia. But mainly when more actions or resources are used. Like if you are familiar with .NET there you can have value types and reference types. Reference types have memory overhead as they require more memory than value types.

无风消散 2024-09-09 04:41:01

开销的一个具体示例是“本地”过程调用和“远程”过程调用之间的差异。

例如,对于经典的 RPC(以及许多其他远程框架,如 EJB),函数或方法调用对于编码人员来说看起来都是一样的,无论是本地内存调用还是分布式网络调用。

例如:

service.function(param1, param2);

这是普通方法还是远程方法?从你在这里看到的你无法判断。

但您可以想象,两个调用之间的执行时间差异是巨大的。

因此,虽然核心实现“成本相同”,但涉及的“开销”却截然不同。

A concrete example of overhead is the difference between a "local" procedure call and a "remote" procedure call.

For example, with classic RPC (and many other remote frameworks, like EJB), a function or method call looks the same to a coder whether its a local, in memory call, or a distributed, network call.

For example:

service.function(param1, param2);

Is that a normal method, or a remote method? From what you see here you can't tell.

But you can imagine that the difference in execution times between the two calls are dramatic.

So, while the core implementation will "cost the same", the "overhead" involved is quite different.

小女人ら 2024-09-09 04:41:01

将开销视为管理线程和协调线程所需的时间。如果线程没有足够的任务要做,这就是一种负担。在这种情况下,开销成本超过了通过使用线程节省的时间,并且代码比顺序代码花费更多的时间。

Think about the overhead as the time required to manage the threads and coordinate among them. It is a burden if the thread does not have enough task to do. In such a case the overhead cost over come the saved time through using threading and the code takes more time than the sequential one.

飘落散花 2024-09-09 04:41:01

为了回答你,我会举一个煮米饭的类比。

理想情况下,当我们想要做饭时,我们希望一切都可用,我们希望锅已经干净,米饭有足够的数量。如果这是真的,那么我们煮饭的时间就会减少(管理费用就会减少)。

另一方面,假设您没有立即获得干净的水,您没有大米,因此您需要先从商店购买,并且还需要从屋外的水龙头获取干净的水。这些额外的任务不是标准的,或者让我说,煮饭你不一定要花那么多时间收集原料。理想情况下,您在煮饭时必须准备好食材。

因此,从商店买米和从水龙头取水所花费的时间成本都是煮饭的间接费用。与标准的煮饭方式相比,这些成本是我们可以避免或最小化的(一切都在你身边,你不必浪费时间收集原料)。

收集原料所浪费的时间就是我们所说的间接费用。

在计算机科学中,例如在多线程中,当线程必须轮流相互访问某个资源或者相互传递信息或数据时,线程之间就会产生通信开销。上下文切换会产生开销。尽管这对他们来说至关重要,但与传统的单线程编程方式相比,这只是时间(CPU 周期)的浪费,而传统的单线程编程方式在通信中永远不会浪费时间。单线程程序可以立即完成这项工作。

To answer you, I would give you an analogy of cooking Rice, for example.

Ideally when we want to cook, we want everything to be available, we want pots to be already clean, rice available in enough quantities. If this is true, then we take less time to cook our rice( less overheads).

On the other hand, let's say you don't have clean water available immediately, you don't have rice, therefore you need to go buy it from the shops first and you need to also get clean water from the tap outside your house. These extra tasks are not standard or let me say to cook rice you don't necessarily have to spend so much time gathering your ingredients. Ideally, your ingredients must be present at the time of wanting to cook your rice.

So the cost of time spent in going to buy your rice from the shops and water from the tap are overheads to cooking rice. They are costs that we can avoid or minimize, as compared to the standard way of cooking rice( everything is around you, you don't have to waste time gathering your ingredients).

The time wasted in collecting ingredients is what we call the Overheads.

In Computer Science, for example in multithreading, communication overheads amongst threads happens when threads have to take turns giving each other access to a certain resource or they are passing information or data to each other. Overheads happen due to context switching.Even though this is crucial to them but it's the wastage of time (CPU cycles) as compared to the traditional way of single threaded programming where there is never a time wastage in communication. A single threaded program does the work straight away.

翻身的咸鱼 2024-09-09 04:41:01

它是除数据本身之外的任何内容,即 tcp 标志、标头、crc、fcs 等。

its anything other than the data itself, ie tcp flags, headers, crc, fcs etc..

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文