Virtual Functions and Performance C++

后端 未结 8 629
梦毁少年i
梦毁少年i 2021-01-18 04:10

Before you cringe at the duplicate title, the other question wasn\'t suited to what I ask here (IMO). So.

I am really wanting to use virtual functions in my applicat

8条回答
  •  無奈伤痛
    2021-01-18 04:26

    I believe that your test case is too artificial to be of any great value.

    First, inside your profiled function you dynamically allocate and deallocate an object as well as call a function, if you want to profile just the function call then you should do just that.

    Second, you are not profiling a case where a virtual function call represents a viable alternative to a given problem. A virtual function call provides dynamic dispatch. You should try profiling a case such as where a virtual function call is used as an alternative to something using a switch-on-type anti-pattern.

提交回复
热议问题