// from: https://gist.github.com/teknoraver/ebee75c5bc4eb8533b8e761d0e57b7d9 // ctx_clock Copyright (C) 2018 Matteo Croce // a tool measure the context switch time in clock cycles #include #include #include #include int main() { unsigned junk; unsigned long long cycles = std::numeric_limits::max(); for (int i = 0; i < 1'000'000; ++i) { auto start = __rdtscp(&junk); syscall(-1L); cycles = std::min(cycles, __rdtscp(&junk) - start); } std::cout << "context switch: " << cycles << " cycles" << std::endl; }