Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- #include <time.h>
- #define ITERATIONS 1000000
- #define BENCHMARKS 20
- double leibniz(int iter) {
- double n = 1.0;
- for (int i = 2; i <= iter - 1; i++) {
- n += pow(-1.0, i - 1.0) / (i * 2.0 - 1.0);
- }
- return n * 4.0;
- }
- int main() {
- double result;
- double total_time = 0;
- clock_t begin, end;
- for (int i = 0; i < BENCHMARKS; i++) {
- begin = clock();
- result = leibniz(ITERATIONS);
- end = clock();
- total_time += (double)(end - begin);
- }
- printf("%8lf\n", result);
- printf("Avg execution time: %8lf\n", total_time / BENCHMARKS / CLOCKS_PER_SEC);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement