What is pessimization?

前端 未结 3 760
甜味超标
甜味超标 2021-02-20 01:30

There is a comment on the question Can the use of C++11\'s auto improve performance? that scored many votes and suggests “makes it less likely to unintentionally pessimize” as a

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-20 02:13

    Pessimizing implies a little more than just giving performance that isn't the best it could be.

    In general, it's doing something, typically in the interest of improving performance, that actually hurts performance instead. Although not absolutely required, there's frequently the implication that the result is actually worse than if you'd just done something simple and obvious.

    In this case, using auto to specify the type of the variable is simple and obvious--and regardless of whether it's precisely optimum, it establishes a baseline level of performance. When/if you specify the type explicitly, you basically just end up with two choices: explicitly define the same type auto would have deduced (getting exactly the same performance), or specifying some other type (in which case there are really only two possibilities: it won't work at all, or it'll do some sort of conversion that almost inevitably hurts performance).

    Summary: pessimization isn't usually just "getting less that optimal performance". It's usually "doing extra work (possibly in the hope of improving performance) that actually hurts performance."

提交回复
热议问题