What is more efficient a switch case or an std::map

前端 未结 6 1091
星月不相逢
星月不相逢 2020-12-28 13:57

I\'m thinking about the tokenizer here.
Each token calls a different function inside the parser.
What is more efficient:

  • A map of std::functions/boos
6条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-28 14:34

    What is your definition of "efficient"? If you mean faster, then you probably should profile some test code for a definite answer. If you're after flexible and easy-to-extend code though, then do yourself a favor and use the map approach. Everything else is just premature optimization...

提交回复
热议问题