为什么用C的strcmp会比C++的compare快这么多????
#include<iostream>
#include<string>
#include <ctime>
using namespace std;
void main()
{
clock_t start;
string strname="luyajun",strfind="liaoyan";
char *cstrname="luyajun",*cstrfind="liaoyan";
start=clock();
const long sleep=10000000;
for(int i=0;i<sleep;i++)
{
strcmp(cstrname,cstrfind);
}
printf("循环%d次,C strcmp所用时间为:%2.4f\n",sleep,(double)(clock()-start)/CLOCKS_PER_SEC);
start=clock();
for(int i=0;i<sleep;i++)
{
strname.compare(strfind);
}
printf("循环%d次,C++String类所用时间为:%2.4f\n",sleep,(double)(clock()-start)/CLOCKS_PER_SEC);
}
上面程序在我的系统上C的strcmp是0.1100,C++的compare是6.2490????