小编aja*_*xhe的帖子

为什么用户编写的构造函数会影响生成的程序集?

测试环境:vs 2008,调试模式

测试代码是:

// a demo for return value

class C
{
public:
    int value;
    int value2;
    int value3;

    //C(int v=0): value(v) {};
};

C getC(int v)
{
    C c1;

    return c1;
}



int main()
{
    C c1 = getC(10);

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

而asm输出是:

; 39   :    C c1 = getC(10);

push    10                  ; 0000000aH
lea eax, DWORD PTR $T2595[ebp]
push    eax
call    ?getC@@YA?AVC@@H@Z          ; getC
add esp, 8
mov ecx, DWORD PTR [eax]
mov DWORD PTR $T2594[ebp], ecx
mov …
Run Code Online (Sandbox Code Playgroud)

c++ compiler-construction compilation

7
推荐指数
1
解决办法
276
查看次数

指针和数组之间的效率(较少的汇编指令不会花费更少的时间)

有些人说:"任何可以通过数组下标实现的操作也可以通过指针来完成.指针版本通常会更快".

我怀疑上面的结果,所以我做了以下测试:

在下面的文章中,我们不关心编译器优化.关于编译器优化如何影响指针和数组之间的效率,请注意:效率:数组与指针

(Visual Studio 2010,调试模式,无优化)

#include <windows.h>
#include <stdio.h>

int main()
{
    int a[] = {10,20,30};
    int* ap = a;

    long counter;

    int start_time, end_time;
    int index;

    start_time = GetTickCount();
    for (counter = 1000000000L; counter>0; counter--)
    {
        *(ap+1) = 100;
    }
    end_time = GetTickCount();
    printf("10 billion times of *ap = %d\n", end_time-start_time);

    start_time = GetTickCount();
    for (counter = 1000000000L; counter>0; counter--)
    {
        a[1] = 101;
    }
    end_time = GetTickCount();
    printf("10 billion times of a[0] = %d\n", end_time-start_time);

    return …
Run Code Online (Sandbox Code Playgroud)

c assembly visual-studio-2010

6
推荐指数
1
解决办法
423
查看次数

为什么 GetTickCount 和 timeGetTime 有不同的分辨率?

默认情况下,GetTickCount 和 timeGetTime 具有相同的分辨率 - 15.625ms,但是在我调用 timeBeginPeriod(1) 之后,GetTickCount 仍然每 15.625 ms 更新一次,而 timeGetTime 每 1ms 更新一次,这是为什么?

等待计时器中的错误?,作者提到:

基于 RTC 的定时器

我想知道:为什么GetTickCount和timeGetTime来自同一个RTC,但有两种分辨率?

谢谢!

windows timer performancecounter gettickcount

5
推荐指数
1
解决办法
3885
查看次数