c++ - 在哪里可以找到不同 STL 容器复杂性(性能)的比较?

标签 c++ performance stl complexity-theory

<分区>

我在谷歌上搜索了很长时间,以便找到一个比较,该比较显示了所有 STL 容器在插入/推送删除/弹出等方面的复杂性差异。我没有找到任何东西。也不在我所有的 STL 书籍中。有什么提示吗?

我当然知道一些经验法则。但是定义在哪里呢?

最佳答案

尝试

http://www.sgi.com/tech/stl/complexity.html

http://www.sgi.com/tech/stl/table_of_contents.html

来自 complexity.html:

Fundamentally, it is difficult to define the notion of asymptotic algorithm complexity precisely for real computer hardware instead of an abstract machine model. Thus we settle for the following guidelines:

  1. For an algorithm A to have running time O(f(n)), there must be a corresponding algorithm A' that is correct on machines with arbitrarily long pointer and size_t types, such that A and A' perform essentially the same sequence of operations on the actual hardware. (In simple cases A and A' will be the same. In other cases A may have been simplified with the knowledge that adresses are bounded.) For inputs of sufficiently large size n, A' must take at most time Cf(n), where C is a constant, independent of both n and the address size. (Pointer, size_t, and ptrdiff_t operations are presumed to take constant time independent of their size.)
  2. All container or iterator complexity specifications refer to amortized complexity. An individual operation may take longer than specified. But any sufficiently long sequence of operations on the same container or iterator will take at most as long as the corresponding sum of the specified operation costs.
  3. Algorithms specify either worst-case or average case performance, and identify which. Unless otherwise stated, averages assume that container elements are chosen from a finite type with more possible values than the size of the container, and that container elements are independently uniformly distributed.
  4. A complexity specification for an operation f assumes that operations invoked by f require at most the specified runtime. But algorithms generally remain appropriate if the invoked operations are no more than a logarithmic factor slower than specified in the expected case.
  5. If operations are more expensive than assumed by a function F in the current STL, then F will slow down at most in proportion to the added cost. Any future operations that fail to satisfy this property will make that explicit.

    To make this precise, assume F is specified to use time f(m) for input of size m. F uses operations Gk, with specified running times gk(n) on input size n. If F is used in a context in which each Gk is slower than expected by at most a factor h(n), then F slows down by at most a factor h(m). This holds because none of the current algorithms ever apply the operations Gk to inputs significantly larger than m.

关于c++ - 在哪里可以找到不同 STL 容器复杂性(性能)的比较?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1049041/

相关文章:

c++ - 如何在 C++ 中打印变量名?

java - 为什么在我实现的插入排序中处理有序数组时,通用版比专用版慢4倍?

performance - Erlang VM 是否为 CPU 的每个硬件核心创建单线程?

c++ - 减少 gdb 打印中的垃圾

c++ - 抑制单行的弃用警告

c++ - 如何处理文件中的位?

c++ - 使用 inputMask 时不显示 TextFields 中的 placeholderText

java - 最高效 - 性能明智 - 用于 JVM 间通信

c++ - 为什么使用 find_first_or_default 函数扩展 std 命名空间会阻止模板推导工作

c++ - STL 容器元素销毁顺序