-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpage135.cpp
More file actions
27 lines (24 loc) · 918 Bytes
/
Copy pathpage135.cpp
File metadata and controls
27 lines (24 loc) · 918 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>
#include <ctime>
int main(){
int n = 100000000;
double d, dpi = 3.1415926535897923385;
float f, fpi = 3.1415926535897932384;
time_t tm0 = time(nullptr);
clock_t ck0 = clock();
for(int i = 0; i < n; i++) d = (double(i) +dpi)*dpi;
time_t tm1 = time(nullptr);
clock_t ck1 = clock();
std::cout << "wall time = " << difftime(tm1,tm0) << " seconds" <<\
std::endl;
std::cout << "CPU time = " << double(ck1 - ck0)/CLOCKS_PER_SEC <<\
"seconds" << std::endl;
for(int i = 0; i < n; i++) f = (double(i) +fpi)*fpi;
time_t tm2 = time(nullptr);
clock_t ck2 = clock();
std::cout << "wall time = " << difftime(tm2,tm1) << " seconds" <<\
std::endl;
std::cout << "CPU time = " << double(ck2 - ck1)/CLOCKS_PER_SEC <<\
"seconds" << std::endl;
std::cout << "The current time is: " << ctime(&tm2) << std::endl;
}