Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #define Inf 1000*1000*1000
- #include <iostream>
- #include <chrono>
- #include <ctime>
- #include <cmath>
- using namespace std;
- using namespace chrono;
- int main() {
- srand(static_cast<unsigned int>(time(0)));
- double val;
- time_point<high_resolution_clock> start, end;
- start = high_resolution_clock::now();
- for (int i = 0; i < Inf; i++) {
- val = (double)rand() / RAND_MAX;
- val = val * val;
- }
- end = high_resolution_clock::now();
- duration<int64_t, nano> dur_ns = (end - start);
- unsigned long long elapsed_seconds = dur_ns.count();
- cout << "val*val: " << elapsed_seconds << endl;
- start = high_resolution_clock::now();
- for (int i = 0; i < Inf; i++) {
- val = (double)rand() / RAND_MAX;
- val = val * val;
- }
- end = high_resolution_clock::now();
- dur_ns = (end - start);
- elapsed_seconds = dur_ns.count();
- cout << "*=val: " << elapsed_seconds << endl;
- start = high_resolution_clock::now();
- for (int i = 0; i < Inf; i++) {
- val = (double)rand() / RAND_MAX;
- val = pow(val, 2);
- }
- end = high_resolution_clock::now();
- dur_ns = (end - start);
- elapsed_seconds = dur_ns.count();
- cout << "pow: " << elapsed_seconds << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment