mirror of
https://github.com/TheAlgorithms/C
synced 2025-04-13 17:02:54 +03:00
using the new function_timer library
This commit is contained in:
parent
d24b6ea344
commit
2d9d2d87fe
@ -1,10 +1,10 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#ifdef _OPENMP
|
#ifdef _OPENMP
|
||||||
#include <omp.h>
|
#include <omp.h>
|
||||||
#endif
|
#endif
|
||||||
|
#include "function_timer.h"
|
||||||
|
|
||||||
unsigned long MAX_N = 28123;
|
unsigned long MAX_N = 28123;
|
||||||
|
|
||||||
@ -91,26 +91,28 @@ int main(int argc, char **argv)
|
|||||||
printf("Not using parallleization!\n");
|
printf("Not using parallleization!\n");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
clock_t dt = 0;
|
double total_duration = 0;
|
||||||
|
function_timer *timer = new_timer();
|
||||||
#ifdef _OPENMP
|
#ifdef _OPENMP
|
||||||
#pragma omp parallel for reduction(+ \
|
#pragma omp parallel for reduction(+ \
|
||||||
: sum) schedule(runtime)
|
: sum) schedule(runtime)
|
||||||
#endif
|
#endif
|
||||||
for (unsigned long i = 1; i <= MAX_N; i++)
|
for (unsigned long i = 1; i <= MAX_N; i++)
|
||||||
{
|
{
|
||||||
clock_t start_time = clock();
|
start_timer(timer);
|
||||||
if (!is_sum_of_abundant(i))
|
if (!is_sum_of_abundant(i))
|
||||||
sum += i;
|
sum += i;
|
||||||
clock_t end_time = clock();
|
clock_t end_time = clock();
|
||||||
dt += end_time - start_time;
|
total_duration += end_timer(timer);
|
||||||
|
|
||||||
printf("... %5lu: %8lu\r", i, sum);
|
printf("... %5lu: %8lu\r", i, sum);
|
||||||
if (i % 100 == 0)
|
if (i % 100 == 0)
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("Time taken: %.4g ms\n", 1e3 * dt / CLOCKS_PER_SEC);
|
printf("Time taken: %.4g s\n", total_duration);
|
||||||
printf("Sum of numbers that cannot be represented as sum of two abundant numbers : %lu\n", sum);
|
printf("Sum of numbers that cannot be represented as sum of two abundant numbers : %lu\n", sum);
|
||||||
|
|
||||||
|
delete_timer(timer);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user