Created
May 3, 2020 15:19
-
-
Save martin-ueding/4d9d91dae92100885b4e9a9a0a5679a7 to your computer and use it in GitHub Desktop.
Test of various clock implementations -- https://martin-ueding.de/posts/clock-test/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright © 2016 Martin Ueding <mu@martin-ueding.de> | |
// Test the cost of various time implementations. | |
#include <mpi.h> | |
#include <omp.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <time.h> | |
void pretty_print(const double start, | |
const double stop, | |
const char *const method, | |
const long runs) { | |
const double duration = (stop - start) / runs; | |
printf("%20s: %g s\n", method, duration); | |
} | |
int main(int argc, char **argv) { | |
MPI_Init(&argc, &argv); | |
double start, stop; | |
const long runs = 10000000; | |
start = omp_get_wtime(); | |
for (long run = 0; run != runs; ++run) { | |
MPI_Wtime(); | |
} | |
stop = omp_get_wtime(); | |
pretty_print(start, stop, "MPI_Wtime", runs); | |
start = omp_get_wtime(); | |
for (long run = 0; run != runs; ++run) { | |
omp_get_wtime(); | |
} | |
stop = omp_get_wtime(); | |
pretty_print(start, stop, "omp_get_wtime", runs); | |
start = omp_get_wtime(); | |
for (long run = 0; run != runs; ++run) { | |
clock(); | |
} | |
stop = omp_get_wtime(); | |
pretty_print(start, stop, "clock", runs); | |
start = omp_get_wtime(); | |
for (long run = 0; run != runs; ++run) { | |
} | |
stop = omp_get_wtime(); | |
pretty_print(start, stop, "none", runs); | |
MPI_Finalize(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment