小编Ste*_*Mai的帖子

从寄存器移动到频繁访问的变量时性能意外降低

我正在使用以下示例了解缓存的工作原理:

\n
#include <stdio.h>\n#include <stdint.h>\n#include <stdlib.h>\n\ntypedef uint32_t data_t;\nconst int U = 10000000;   // size of the array. 10 million vals ~= 40MB\nconst int N = 100000000;  // number of searches to perform\n\nint main() {\n  data_t* data = (data_t*) malloc(U * sizeof(data_t));\n  if (data == NULL) {\n    free(data);\n    printf("Error: not enough memory\\n");\n    exit(-1);\n  }\n\n  // fill up the array with sequential (sorted) values.\n  int i;\n  for (i = 0; i < U; i++) {\n    data[i] = i;\n  }\n\n  printf("Allocated array of …
Run Code Online (Sandbox Code Playgroud)

c assembly caching x86-64 perf

3
推荐指数
1
解决办法
138
查看次数

标签 统计

assembly ×1

c ×1

caching ×1

perf ×1

x86-64 ×1