Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <sched.h>
- #include <stdio.h>
- #include <time.h>
- static long nanotime() {
- struct timespec tp;
- clock_gettime(CLOCK_MONOTONIC, &tp);
- return tp.tv_sec * 1000000000L + tp.tv_nsec;
- }
- static void measure_yield() {
- long times[10];
- int i;
- for (i = 0; i < 10; i++) {
- long start_time = nanotime();
- sched_yield();
- times[i] = nanotime() - start_time;
- }
- printf("[%ld %ld %ld %ld %ld %ld %ld %ld %ld %ld]\n",
- times[0], times[1], times[2], times[3], times[4],
- times[5], times[6], times[7], times[8], times[9]);
- }
- int main() {
- int i;
- for (i = 0; i < 10; i++) {
- measure_yield();
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment