-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathsy.c
41 lines (32 loc) · 884 Bytes
/
sy.c
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
34
35
36
37
38
39
40
#include <sys/time.h>
#include <time.h>
#include <stdio.h>
#include <sched.h>
#include <sys/mman.h>
#include "util.h"
#include "rdtscp.h"
#define ITERATIONS 500000
uint64_t times[ITERATIONS];
int main(int argc, char *argv[]) {
uint64_t t1, t2, total_cycles;
int i;
memset(times, 0, sizeof(times));
t1 = rdtscp();
for (i = 0; i < ITERATIONS; i++) {
sched_yield();
}
t2 = rdtscp();
total_cycles = t2 - t1;
t1 = rdtscp();
for (i = 0; i < ITERATIONS; i++) {
sched_yield();
t2 = rdtscp();
times[i] = t2 - t1;
t1 = t2;
}
sort_uint64_t_array(times, ARRAY_SIZE(times));
printf("Average cycles per sched_yield: %lu\n", total_cycles / ITERATIONS);
printf("Minimum cycles per iteration: %lu\n", times[0]);
printf("Median cycles per iteration: %lu\n", times[ARRAY_SIZE(times) / 2]);
printf("95th percentile cycles per iteration: %lu\n", times[P(95, times)]);
}