dynamic_cast<>有多快? [英] How fast is dynamic_cast<>

查看:52
本文介绍了dynamic_cast<>有多快?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

... 与典型的 std::string::operator==() 相比?我在下面提供了更多细节,我不确定它们是否有任何相关性.具有复杂性或近似性的答案就足够了.谢谢!

... approximately compared to a typical std::string::operator==()? I give some more details below, I'm not sure if they are of any relevance. Answer with complexity or approximation is good enough. Thanks!

详细信息: 我将在列表的 for 循环中使用它来查找某些特定实例.我估计我的平均继承水平为 3.5 个类.我正在寻找的那个有一个父类,一个祖父类和两个接口"之上,即用几个 virtual void abc() = 0; 抽象类.

Details: I will use it inside a for loop over a list to find some specific instances. I estimate my average level of inheritance to 3.5 classes. The one I'm looking for has a parent class, a grandparent and above that two "interfaces", i.e. to abstract classes with a couple of virtual void abc() = 0;.

我要寻找的没有子类.

推荐答案

这在很大程度上取决于您的编译器、特定的类层次结构、硬件以及各种因素.您确实需要直接在您的特定应用程序中对其进行测量.您可以使用 rdtsc 或(在 Windows 上)QueryPerformanceCounter 以获得一个相对高精度的计时器.确保对数千个 dynamic_cast<> 的循环或雪橇计时,因为即使 QPC 的分辨率只有 ?

It depends hugely on your compiler, your particular class hierarchy, the hardware, all sorts of factors. You really need to measure it directly inside your particular application. You can use rdtsc or (on Windows) QueryPerformanceCounter to get a relatively high-precision timer for that purpose. Be sure to time loops or sleds of several thousand dynamic_cast<>s, because even QPC only has a ¼μs resolution.

在我们的应用中,一个 dynamic_cast<> 花费大约 1 微秒,而一个字符串比较大约 3ns/字符.

In our app, a dynamic_cast<> costs about 1 microsecond, and a string comparison about 3ns/character.

dynamic_cast<> 和 stricmp() 都在我们的配置文件的顶部,这意味着使用它们的性能成本非常高.(坦率地说,在我们的工作领域,将这些函数放在如此重要的位置是不可接受的,我不得不去重写一堆其他人使用它们的代码.)

Both dynamic_cast<> and stricmp() are at the top of our profiles, which means the performance cost of using them is significant. (Frankly in our line of work it's unacceptable to have those functions so high on the profile and I've had to go and rewrite a bunch of someone else's code that uses them.)

这篇关于dynamic_cast&lt;&gt;有多快?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆