- 论坛徽章:
- 0
|
本帖最后由 zhangsuozhu 于 2011-01-03 18:43 编辑
相同的代码。300倍的速度差别。GCC真老了!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #include <string.h>
- int main()
- {
- char s[] = " select * from aaaa where id=1;select name ,id from bbbb";
- int i,j;
- int t = time(NULL);
- char *p = NULL;
- for (i = 0; i < 100000000; i ++)
- {
- j = i%sizeof(s)-1;
- s[j] = ((j&0xff)+(i&0xff))&0xff;
- p = s;
- while(*p != '\0')
- {
- if (strstr(p, "abs w fs e w fw"))
- {
- break;
- }
- else
- {
- p ++;
- }
- }
-
- }
- printf("%lu\n",time(NULL) -t);
- return 0;
- }
复制代码 makefile:
- llvm:
- llvm-gcc -O3 -Wall -o test test.c
- gcc:
- gcc -O3 -Wall -o test test.c
复制代码 对比测试:
用llvm的 1秒
用gcc的 317秒
300多倍的差别。求验证! 求高手优化GCC |
|