一晃竟然已经十年,各家的宝宝已经满地跑,而我们,也都变得大腹便便。
十年后,我们又相聚海大。
Profiling in software
In software engineering, performance analysis, more commonly known today as profiling, is the investigation of a program’s behavior using information gathered as the program executes (i.e. it is a form of dynamic program analysis, as opposed to static code analysis). The usual goal of performance analysis is to determine which sections of a program to optimize — usually either to increase its speed or decrease its memory requirement (or sometimes both).
continue to read online:
If you want to manipulate the bit in BYTE array, following functions are useful to you.
BYTE GetBit(BYTE* pBuffer, int nBit)
{
int bitOffset = nBit & 7;
BYTE ret = pBuffer[nBit >> 3] >> bitOffset;
ret &= 1;
return ret;
}
void SetBit(BYTE* pBuffer, int nBit)
{
BYTE val = 1 << (nBit & 7);
pBuffer[nBit >> 3] |= val;
}
For the GetBit, nBit is the bit offset you want to test.
nBit & 7 is equal to nBit % 8, it will get bit offset for input parameter nBit.
nBit >> 3 is equal to nBit / 8, it will get the byte offset in Byte array.
Why we use bit operations instead of mod and div operation? The reason is simple, for the bit operation, it will generate more fast and simple assembly code. You could see my build result like:
; 160 : unsigned int modVal = i % 8;
mov eax, DWORD PTR _i$[ebp]
xor edx, edx
mov ecx, 8
div ecx
mov DWORD PTR _modVal$[ebp], edx
; 161 :
; 162 : unsigned int andVal = i & 7;
mov eax, DWORD PTR _i$[ebp]
and eax, 7
mov DWORD PTR _andVal$[ebp], eax
The code is generated by VC2008 and disabled optimization. For mod operation "i % 8", it has "div" and will be slow then "i & 7".
最近在复习c(c++)语言里面的复杂声明,这个东西真是麻烦的紧啊。