64,647
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <cstring>
//#include <string>
//using std::string;
int main()
{
/*string str("a very long literal string");
for(int ix = 0; ix != 1000000;++ix)
{
string str2=str;
if(str==str2)
;
}*/
const char *pc = "a very long literal string";
const size_t len = strlen(pc);
for(size_t ix = 0;ix != 1000000;++ix)
{
char *pc2 = new char[len+1];
strcpy(pc2,pc);
if(strcmp(pc2,pc))
;
delete [] pc2;
}
return 0;
}
#include <iostream>
//#include <cstring>
#include <string>
//using std::string;
#include <time.h>
using namespace::std;
int main()
{
clock_t cts,cte;
cts = clock();
long tm=1000000;
string str("a very long literal string");
for(int ix = 0; ix != tm;++ix)
{
string str2=str;
if(str==str2);
}
/*
const char *pc = "a very long literal string";
const size_t len = strlen(pc);
for(size_t ix = 0;ix != tm;++ix)
{
char *pc2 = new char[len+1];
strcpy(pc2,pc);
if(strcmp(pc2,pc));
delete [] pc2;
}
*/
cte = clock();
double tt= (double) cte-cts;
cout<<tt<<endl;
return 0;
}
int main()
{
clock_t start, end;
double duration;
start = clock();
string str("a very long literal string");
for(int ix = 0; ix != 1000000;++ix)
{
string str2=str;
if(str==str2)
;
}
/*
const char *pc = "a very long literal string";
const size_t len = strlen(pc);
for(size_t ix = 0;ix != 1000000;++ix)
{
char *pc2 = new char[len+1];
strcpy(pc2,pc);
if(strcmp(pc2,pc))
;
delete [] pc2;
}
*/
end = clock();
duration = (double)(end - start) / CLOCKS_PER_SEC;
printf("time:%f",duration);
system("pause");
return 0;
}