Skip to content

Instantly share code, notes, and snippets.

@sumerc
Last active January 16, 2020 20:46
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 sumerc/d0a034f5718bfe4e271cb6e364397ce2 to your computer and use it in GitHub Desktop.
Save sumerc/d0a034f5718bfe4e271cb6e364397ce2 to your computer and use it in GitHub Desktop.
profile different clock types - Linux
#include "time.h"
#include <sys/time.h>
#include <stdio.h>
#include <stdlib.h>
# include <sys/resource.h>
struct timeval curtime;
struct timespec tp;
struct rusage usage;
int main(int argc, char **argv)
{
int iterations = atoi(argv[1]);
int clk_type = atoi(argv[2]);
for (int i = 0; i < iterations; i++)
{
switch(clk_type) {
case 1:
gettimeofday(&curtime, NULL);
break;
case 2:
clock_gettime(CLOCK_MONOTONIC, &tp);
break;
case 3:
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &tp);
break;
case 4:
clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tp);
break;
case 5:
getrusage(RUSAGE_SELF, &usage);
break;
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment