llvm vs gcc 我被雷到了, 速度相差300多倍,你还用GCC吗!【转】

来源:互联网 发布:小站托福有mac版吗 编辑:程序博客网 时间:2024/05/23 00:07

相同的代码。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&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秒

0 0
原创粉丝点击