辅导:计算程序时间的方法
来源:优易学  2011-10-6 11:08:21   【优易学:中国教育考试门户网】   资料下载   IT书店
  void time_one()
  {
  LARGE_INTEGER one;
  LARGE_INTEGER two;
  LARGE_INTEGER freq;
  QueryPerformanceFrequency(&freq);
  QueryPerformanceCounter(&one);
  for (int i = 0; i < 1000000000; i++)
  {
  }
  QueryPerformanceCounter(&two);
  cout << two.QuadPart * 1.0 / freq.QuadPart - one.QuadPart * 1.0 / freq.QuadPart << endl;
  }
  void time_two()
  {
  double timeStart = GetTickCount();
  for (int i = 0; i < 10000000; i++)
  {
  }
  double timeEnd = GetTickCount();
  cout << timeEnd - timeStart << endl;
  }
  void time_three()
  {
  time_t stime;
  time_t etime;
  time(&stime);
  getchar();
  time(&etime);
  printf(\"%ld\\n\",etime - stime);
  }
  void time_four()
  {
  double begin=(double)clock()/CLK_TCK;
  for (int i = 0; i < 1000000000; i++)
  {
  }
    double end=(double)clock()/CLK_TCK;
    cout << end - begin << endl;
  }
  void time_five()
  {
    clock_t t1 = clock();
    for (int i = 0; i < 1000000000; i++)
  {
  }
    clock_t t2 = clock();
    cout<<\"Total time = \"<<t2-t1<<endl;
  }

责任编辑:小草

文章搜索:
 相关文章
热点资讯
资讯快报
热门课程培训