Last active
January 16, 2020 20:46
-
-
Save sumerc/d0a034f5718bfe4e271cb6e364397ce2 to your computer and use it in GitHub Desktop.
profile different clock types - Linux
This file contains hidden or 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
#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