测试数据生成

 要生成300亿的文本数据,刚开始用python,实在是太慢了,改成c后速度提升了10几倍,看来干大事还是不能用python。代码留一下,以后可能还可以用上。

#include 
#include 
#include 

int main(int argc, char *argv[])
{

        if (argc != 4)
        {
                printf("[%d]o.exe filename startnum endnum \n",argc);
                return 1;
        }

        srand((unsigned)time(NULL));

        FILE* pf;
        char* filename = argv[1];
        pf = fopen(filename,"w");
        if (pf != NULL)
        {
                long i = strtoul(argv[2],NULL,0);
                long e = strtoul(argv[3],NULL,0);
                for (;i<=e;i++)
                {
                        double r = ((double)rand() / RAND_MAX) *10000000000;
                        int r1 = rand()%10;
                        fprintf(pf,"INDEXA%ld,2023-08-25,ORG%d,%10.3F\n",i,r1,r);
                        //printf("2023-08-24,INDEXA%ld,ORG%d,%10.3F\n",i,r1,r);
                }
                fclose(pf);
        }
        return 0;
}
#编译
gcc gen.c


#生成300亿行数据
./a.out imp.csv 1 300000000000

你可能感兴趣的:(c++,c)