Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Test of various clock implementations -- https://martin-ueding.de/posts/clock-test/
// 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