非专业程序员

  :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <bitset>
  5. #include <cstddef>
  6. #include <ctime>
  7. using namespace std;
  8. int main()
  9. {
  10.     const char *pc="A very long string ,test C and C++ speed!";
  11.     const size_t len=strlen(pc);
  12.     clock_t  t1,t2;
  13.     t1=clock();
  14.     for(size_t ix=0;ix!=100000;++ix)
  15.     {
  16.         char *pc2=new char[len+1];
  17.         strcpy(pc2,pc);
  18.         if(strcmp(pc,pc2))
  19.             ;
  20.         delete []pc2;
  21.     }
  22.     t2=clock();
  23.     std::cout<<t2-t1<<endl;
  24.     string s("A very long string ,test C and C++ speed!");
  25.     clock_t m1,m2;
  26.     m1=clock();
  27.     for(size_t ix=0;ix!=100000;++ix)
  28.     {
  29.         string s1(s);
  30.         if(s1!=s)
  31.             ;
  32.     }
  33.     m2=clock();
  34.     std::cout<<m2-m1<<endl;
  35.     
  36. }
posted on 2008-12-26 10:33  曲仁岗  阅读(292)  评论(0编辑  收藏  举报