2
启用优化后,为什么此代码慢6.5倍?
我想基准glibc的strlen功能,出于某种原因,发现它显然执行多慢与GCC启用优化,我不知道为什么。 这是我的代码: #include <time.h> #include <string.h> #include <stdlib.h> #include <stdio.h> int main() { char *s = calloc(1 << 20, 1); memset(s, 65, 1000000); clock_t start = clock(); for (int i = 0; i < 128; ++i) { s[strlen(s)] = 'A'; } clock_t end = clock(); printf("%lld\n", (long long)(end - start)); …
68
c
performance
gcc
glibc