forked from DiamonDinoia/benchmark_arch_optimization_flags
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
executable file
·31 lines (24 loc) · 790 Bytes
/
main.cpp
File metadata and controls
executable file
·31 lines (24 loc) · 790 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
29
30
31
#include <iostream>
#include <ctime>
#include <ratio>
#include <chrono>
using namespace std::chrono;
inline double pi(unsigned long n) {
double sum = 0.0;
int sign = 1;
for (unsigned long i = 0; i < n; ++i) {
sum += sign/(2.0*i+1.0);
sign *= -1;
}
return 4.0*sum;
}
const unsigned long iterations = 1000000000;
int main(){
high_resolution_clock::time_point start = high_resolution_clock::now();
auto value = pi(iterations);
high_resolution_clock::time_point end = high_resolution_clock::now();
std::cout << "iterations " << iterations << " value " << value << std::endl;
duration<double> time_span = duration_cast<duration<double>>(end - start);
std::cout << "time " << time_span.count() << std::endl;
return 0;
}