-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimemark.cpp
More file actions
28 lines (22 loc) · 795 Bytes
/
timemark.cpp
File metadata and controls
28 lines (22 loc) · 795 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
28
#include <iostream>
#include <cmath>
#include <chrono>
int main() {
const int iterations = 1000;
double result = 0.0;
auto start = std::chrono::high_resolution_clock::now();
for (int i = 0; i < iterations; i++) {
for (int j = 0; j < iterations; j++) {
for (int k = 0; k < iterations; k++) {
result += sqrt(i * j * k + 1); // Adding 1 to avoid sqrt(0)
}
}
}
auto end = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> elapsed_time = end - start;
std::cout << "C++ Benchmark:\n";
std::cout << "Time elapsed: " << elapsed_time.count() << " seconds\n";
std::cout << "Result: " << result << std::endl;
std::cout << "---------------------------------\n";
return 0;
}