readm.c
来自「代码优化,有效使用内存,透视优化技术,对比优化方法,如果你在追求代码效率的最大化」· C语言 代码 · 共 41 行
C
41 行
/*----------------------------------------------------------------------------
*
* EXAMPLE DEMONSTRATING INCONSTANCY
* of the memory block processing time
* ======================================
*
* Build 0x001 16.08.2002
----------------------------------------------------------------------------*/
//#define __OVER_BRANCH__
// ^^^^ remove the comments from the previous line to activate "over-branching"
// and saturate the branch prediction block to clear the result from
// introduced distortions
#include <DoCPU.h>
#define BLOCK_SIZE _NORMAL
main()
{
int *p;
int x = 0;
#define a (int *)((char *)p + x)
#define b (int *)((char *)p + BLOCK_SIZE - x)
p = (int *) malloc(BLOCK_SIZE);
PRINT_TITLE; PRINT(("= = = Demonstrating inconstancy of the memory block processing time = = =\n"));
A_BEGIN(0)
for (x = 0; x < BLOCK_SIZE/2; x += sizeof(int))
{
#ifdef __OVER_BRANCH__
if (x & 1)
#endif
*a = *a^*b; *b = *b^*a; *a = *a^*b;
}
A_END(0)
// displaying the result of all measurements
A_LIST_ITER(0)
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?