测试语句运行时间

100W数据查询 ,下面的程序

  有键:select confid from testtime where confid=294142697 ;  时间:0.02sec

  无键:select confid from testtime where confid=294142697 ;  时间:1.54sec



 4 int main()

  5 {
  6     MYSQL *pMysql = NULL;
  7     MYSQL_RES *pMysqlRes = NULL;
  8     MYSQL_FIELD *pMysqlField = NULL;
  9     MYSQL_ROW pMysqlRow = NULL;
 10     unsigned long client_flag = 0;
 11     int iResult = 0;
 12     int i = 0, j = 0;
 13     int iRand;
 14     int index = 1;
 15     struct timeval beforetime;
 16     struct timeval aftertime;
 17     unsigned long long all = 0,all_1=0,all_2=0,all_3=0;
 18 
 19 
 20     bzero(&beforetime,sizeof(beforetime)); 21     bzero(&aftertime,sizeof(aftertime));
 22 
 23 
 24     if ((pMysql = mysql_init(NULL)) == NULL )
 25         printf ("mysql init failed\n");
 26     if ((mysql_real_connect (pMysql, "127.0.0.1", "mysql", "", "test", 3306,
 27                             NULL, client_flag)) == NULL )
 28         printf("connect db wrong\n");
 29     char sql[256]={0};
 30     while(i < 1000) {
 31         while(j <10) {
 32             iRand = rand();
 33             snprintf(sql,sizeof(sql),"insert into testtime \
 34                         values(%d,%d,20161209);",index,iRand);
 35             //printf("sql;%s\n",sql);
 36             gettimeofday(&beforetime, NULL);
 37             //printf("before time=%d\n",beforetime.tv_usec);
 38             iResult = mysql_query(pMysql,sql);
 39             //printf("time=%d\n",aftertime.tv_usec);
 40             gettimeofday(&aftertime, NULL);
 41             if ( i < 300)
 42                 all += (aftertime.tv_sec-beforetime.tv_sec)*1000000+
 43                             aftertime.tv_usec-beforetime.tv_usec;

44             else if ( i >= 300 && i < 600)

 45                 all += (aftertime.tv_sec-beforetime.tv_sec)*1000000+
 46                             aftertime.tv_usec-beforetime.tv_usec;
 47             else if (i >= 600 && i<800)
 48                 all += (aftertime.tv_sec-beforetime.tv_sec)*1000000+
 49                             aftertime.tv_usec-beforetime.tv_usec;
 50             else if (i >= 800)
 51                 all += (aftertime.tv_sec-beforetime.tv_sec)*1000000+
 52                             aftertime.tv_usec-beforetime.tv_usec;
 53 
 54             index++;
 55             if (iResult == 0)
 56                 ;
 57             else
 58             {
 59                 printf("insert mysql failed:%s\n",mysql_error(pMysql));
 60             }
 61             j++;
 62         }
 63         j = 0;
 64         i++;

 65     }


 67     printf("all=%u,all_1=%u,all_2=%u,all_3=%u\n",all,all_1,all_2,all_3);
 68 }


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小喾

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值