- #include <iostream>
- #include <string>
- #include <vector>
- #include <bitset>
- #include <cstddef>
- #include <ctime>
- using namespace std;
- int main()
- {
- const char *pc="A very long string ,test C and C++ speed!";
- const size_t len=strlen(pc);
- clock_t t1,t2;
- t1=clock();
- for(size_t ix=0;ix!=100000;++ix)
- {
- char *pc2=new char[len+1];
- strcpy(pc2,pc);
- if(strcmp(pc,pc2))
- ;
- delete []pc2;
- }
- t2=clock();
- std::cout<<t2-t1<<endl;
- string s("A very long string ,test C and C++ speed!");
- clock_t m1,m2;
- m1=clock();
- for(size_t ix=0;ix!=100000;++ix)
- {
- string s1(s);
- if(s1!=s)
- ;
- }
- m2=clock();
- std::cout<<m2-m1<<endl;
- }
C字符串和C++速度比较
最新推荐文章于 2024-07-18 17:40:16 发布