什么是"开销"?

yuu*_*chi 132 overhead

我是计算机科学专业的学生,​​在谈到程序和各种各样时,我听到了"开销"这个词.这究竟是什么意思?

cor*_*iKa 159

这是设置操作所需的资源.它可能看似无关,但是必要的.

就像你需要去某个地方一样,你可能需要一辆车.但是,要让汽车沿着街道行驶会有很多开销,所以你可能想要走路.但是,如果你要去全国各地,那么开销是值得的.

在计算机科学中,有时我们会使用汽车走在街上,因为我们没有更好的方法,或者我们不值得"学会走路".

  • 类似的比喻就是飞行.飞机比汽车快得多,但机场登机,安全等的开销使得汽车成为较短距离的更好选择. (74认同)
  • "我不值得花时间去学习如何走路." - 史诗:D (16认同)

Mic*_*rdt 36

这个词的含义可以与上下文有很大的不同.通常,它使用的资源(通常是内存和CPU时间)不会直接影响预期结果,但是正在使用的技术或方法需要这些资源.例子:

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


Laz*_*Laz 16

你累了,不能做更多的工作.你吃的食物.寻找食物,获取食物并实际食用它所消耗的能量消耗能量并且是开销!

为了完成任务,开销就浪费了.目标是使开销非常小.

在计算机科学中,我们可以说你想打印一个数字,这就是你的任务.但是存储数字,设置显示以打印它并调用例程来打印它,然后从变量访问数字都是开销.


Mat*_*nes 15

维基百科有我们覆盖:

在计算机科学中,开销通常被认为是实现特定目标所需的过量或间接计算时间,存储器,带宽或其他资源的任何组合.这是工程开销的特例.

  • 但如果没有,你会修复WikiPedia,然后在这里发表同样的帖子. (3认同)

Jus*_*ner 10

开销通常指的是不同编程算法所需的额外资源(内存,处理器,时间等).

例如,插入到平衡二进制树中的开销可能比插入到简单链接列表中的相同插入要大得多(插入将花费更长时间,使用更多处理能力来平衡树,这导致更长的操作时间更长用户).


Jim*_*nis 5

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 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.

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


小智 5

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