Skip to content

Instantly share code, notes, and snippets.

@apangin
Created February 12, 2018 18:28
Show Gist options
  • Save apangin/9b298993d750c2e18ea7e34eb915e244 to your computer and use it in GitHub Desktop.
Save apangin/9b298993d750c2e18ea7e34eb915e244 to your computer and use it in GitHub Desktop.
#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;
}
[6075 778 591 594 588 685 584 591 589 588]
[966 598 598 581 598 588 595 588 591 641]
[725 558 591 558 592 545 592 558 585 558]
[672 578 598 565 594 558 652 561 591 558]
[665 552 591 554 591 571 599 558 594 561]
[668 552 598 565 601 562 588 559 594 554]
[695 558 598 554 585 554 588 558 591 555]
[688 554 591 564 595 565 605 562 588 552]
[685 565 595 558 595 558 598 555 595 558]
[662 558 588 565 595 558 621 551 599 558]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment