⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch4time.cc

📁 C++ source code for book-C++ and Object Oriented Numeric computing for scientists and engineers
💻 CC
字号:
#include <iostream>                     // for output
#include <ctime>                        // for measuring time

int main() {

  using namespace std;

  int n = 100000000;
  time_t tm0 = time(0);                   // wall time at this point 
  clock_t ck0 = clock();                  // clock ticks at this point 

  double d, dpi = 3.1415926535897932385;
  float  f, fpi = 3.1415926535897932385;
  for (int i = 0; i< n; i++) d = (double(i) + dpi)*dpi;

  time_t tm1 = time(0);                   // wall time at this point 
  clock_t ck1 = clock();                  // clock ticks at this point 
  cout << "wall time = " << difftime(tm1, tm0) << " seconds.\n";
  cout << "CPU time = " << double(ck1 -ck0)/CLOCKS_PER_SEC << " seconds.\n";

  for (int i = 0; i< n; i++) f = (float(i) + fpi)*fpi; 

  time_t tm2 = time(0);                   // wall time at this point 
  clock_t ck2 = clock();                  // clock ticks at this point 
  cout << "wall time = " << difftime(tm2, tm1) << " seconds.\n";
  cout << "CPU time = " << double(ck2 -ck1)/CLOCKS_PER_SEC << " seconds.\n";

  cout << "The current time is: " << ctime(&tm2) << "\n";
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -