AI Applications in C++: How costly are virtual functions? What are the possible optimizations?

前端 未结 15 1288
慢半拍i
慢半拍i 2020-12-23 12:43

In an AI application I am writing in C++,

  1. there is not much numerical computation
  2. there are lot of structures for which run-time polymorphism is ne
15条回答
  •  一向
    一向 (楼主)
    2020-12-23 13:10

    The cost is more or less the same than normal functions nowadays for recent CPUS, but they can't be inlined. If you call the function millions times, the impact can be significant (try calling millions of times the same function, for example, once with inline once without, and you will see it can be twice slower if the function itself does something simple; this is not a theoritical case: it is quite common for a lot of numerical computation).

提交回复
热议问题