相对运营成本 [英] Relative cost of operations

查看:45
本文介绍了相对运营成本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!

我一直在寻找一个C ++相对成本的比较表,因为它对所有人都非常有用。我找到了

这个:


printf / scanf 1000

new / delete 800

trig 。功能500

浮点数100

等等...


但它没有说明一些C ++功能,像虚拟

函数。



普通函数相比,调用虚函数的成本是多少?

有谁能告诉我在哪里可以找到C +

+的运营成本表?


谢谢。

PD:对不起我的英语。

Hi!
I have been looking for a comparison table of the relative cost of
operations in C++ because it can be very useful for all. I have found
this:

printf/scanf 1000
new/delete 800
trig. function 500
floating point 100
and so on...

But it doesn′t tell anything about some C++ features, like virtual
functions.
What is the cost of calling a virtual function comparing with a
ordinary function?
Could anyone tell me where can I find tables of operations cost for C+
+?

Thanks.
PD: Sorry for my English.

推荐答案



拨打电话的费用是多少虚拟功能与

普通函数相比较?
What is the cost of calling a virtual function comparing with a
ordinary function?



另一个间接级别。


而不是:


PointerToFunction();


你有:


PointerToVTable-> PointerToFunction();


-
$ b $bTomásóhéilidhe


One more level of indirection.

Instead of having:

PointerToFunction();

you have:

PointerToVTable->PointerToFunction();

--
Tomás ó héilidhe


Tom ?? s ?? h ?? ilidhe写道:
Tom??s ?? h??ilidhe wrote:


:

>调用虚函数的成本是多少与普通功能相比?
>What is the cost of calling a virtual function comparing with a
ordinary function?




另一个间接级别。


而不是:


PointerToFunction();



One more level of indirection.

Instead of having:

PointerToFunction();



实际上,常规函数通常不是通过指针调用,而是直接


Actually, a regular function is often not called through a pointer, but
directly.


你有:


PointerToVTable-> PointerToFunction();
you have:

PointerToVTable->PointerToFunction();



实际上,常见的实现更像是

PointerToObject-> PointerToVTable-> PointerToFunction(),所以它是3额外

间接水平。

Actually, the common implementation is more like
PointerToObject->PointerToVTable->PointerToFunction(), so it''s 3 additional
levels of indirection.


Rolf Magnus:
Rolf Magnus:

>而不是:

PointerToFunction();
>Instead of having:

PointerToFunction();



实际上,常规函数通常不是通过指针调用的,而是直接调用


Actually, a regular function is often not called through a pointer,
but directly.



我不确定你的意思是直接打电话。当一个函数在程序中调用
时,CPU的程序计数器被设置为该函数的地址

。我不知道如何在不使用

的地址的情况下调用该函数。

..


I''m not sure what you mean by "called directly". When a function is
called in a program, the CPU''s program counter is set to the address of
the function. I don''t see how you could call the function without using
its address.
..


>你有:

PointerToVTable-> PointerToFunction();
>you have:

PointerToVTable->PointerToFunction();



实际上,常见的实现更像是

PointerToObject-> PointerToVTable-> PointerToFunction(),所以它是3

额外的间接级别。


Actually, the common implementation is more like
PointerToObject->PointerToVTable->PointerToFunction(), so it''s 3
additional levels of indirection.



如果我们在堆栈上有一个对象,那么它的地址只是从堆栈指针偏移的一个

。所以没有:


跳到(address_of_function);


我们有:


JUMP TO((stack_pointer + offset) - > vtable-> address_of_function);


或更简单:


跳到(address_of_object) - > vtable-> address_of_function);


我认为这相当于另外两个间接级别。在

a CPU上,其时钟频率为2 GHz,周期约为4个时钟,b $ b脉冲,而且间接需要2个周期,我想我们正在寻找在

a延迟8纳秒之后。


-
$ b $bTomásóhéilidhe


If we have an object on the stack, then its address is simply an
offset from the stack pointer. So instead of having:

JUMP TO (address_of_function);

We have:

JUMP TO ( (stack_pointer + offset)->vtable->address_of_function );

Or more simply:

JUMP TO ( address_of_object->vtable->address_of_function );

I think this equates to two more levels of indirection in total. On
a CPU whose clock runs at 2 GHz, and where a cycle is about 4 clock
pulses, and where an indirecton takes 2 cycles, I think we''re looking at
a delay of something like 8 nanoseconds.

--
Tomás ó héilidhe


这篇关于相对运营成本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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