Untitled
unknown
plain_text
2 years ago
890 B
10
Indexable
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/time.h>
#include <unistd.h>
#define N 10000000
int add(int a, int b) {
return a + b;
}
int main() {
struct timeval start_time, end_time;
int i;
float iters = N, total_time = 0;
for (i = 0; i < iters; i++) {
gettimeofday(&start_time, NULL);
getpid();
gettimeofday(&end_time, NULL);
total_time += (end_time.tv_sec - start_time.tv_sec) * 1000000.0 + (end_time.tv_usec - start_time.tv_usec) * 1.0;
}
printf("System call overhead: %f microseconds\n", total_time / iters);
total_time = 0;
for (i = 0; i < iters; i++) {
gettimeofday(&start_time, NULL);
add(0, 1);
gettimeofday(&end_time, NULL);
total_time += (end_time.tv_sec - start_time.tv_sec) * 1000000.0 + (end_time.tv_usec - start_time.tv_usec) * 1.0;
}
printf("Procedure call overhead: %f microseconds\n", total_time / iters);
}Editor is loading...