-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path004.c
More file actions
33 lines (27 loc) · 1011 Bytes
/
004.c
File metadata and controls
33 lines (27 loc) · 1011 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/*
..........................................................................................................................................
Name : 004.c
Author : SHRUTI VERMA
Description : Write a program to measure how much time is taken to execute 100 getppid ( )
system call. Use time stamp counter.
Date : 29 Sep 2025
..........................................................................................................................................
*/
#include<unistd.h>
#include<stdlib.h>
#include<stdint.h>
#include<stdio.h>
static __inline__ uint64_t rdtsc(void) {
unsigned hi, lo;
__asm__ __volatile__("rdtsc" : "=a"(lo), "=d"(hi));
return ((uint64_t)hi << 32) | lo;
}
int main() {
int start = rdtsc();
for(int i=0; i<100; i++) getppid();
int end = rdtsc();
printf("Timestamp Counter Ticks : %lld\n", (unsigned long long) (end - start));
}
/* ------------------------------OUTPUT----------------------------
Timestamp Counter Ticks : 465045
*/