C++ STL Map vs Vector speed

后端 未结 12 1062
日久生厌
日久生厌 2020-12-16 11:56

In the interpreter for my experimental programming language I have a symbol table. Each symbol consists of a name and a value (the value can be e.g.: of type string, int, fu

12条回答
  •  天命终不由人
    2020-12-16 12:38

    a std::map (O(log(n))) or a hashtable ("amortized" O(1)) would be the first choice - use custom mechanisms if you determin it's a bottleneck. Generally, using a hash or tokenizing the input is the first optimization.

    Before you have profiled it, it's most important that you isolate lookup, so you can easily replace and profile it.


    std::map is likely a tad slower for a small number of elements (but then, it doesn't really matter).

提交回复
热议问题