Skip to content

Instantly share code, notes, and snippets.

@martin-ueding
Created May 3, 2020 15:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save martin-ueding/4d9d91dae92100885b4e9a9a0a5679a7 to your computer and use it in GitHub Desktop.
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/
// 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