Core function
struct timespec ts_now, ts_sec;if (clock_gettime(CLOCK_MONOTONIC, &ts_now)) { cout << "Error reading the time" << endl; }auto time1_ns = (long long) ts_now.tv_sec * 1000000000 + (long long) ts_now.tv_nsec;
Sample Example: Check should we uncomment print
#include <iostream>#define test=false;using namespace std;int main() {int nonsense = 0;struct timespec ts_now, ts_sec;if (clock_gettime(CLOCK_MONOTONIC, &ts_now)) { std::cout << "Error reading the time" << std::endl; }auto ts_now_long = (long long) ts_now.tv_sec * 1000000000 + (long long) ts_now.tv_nsec;//submit the orderfor(auto _ = 0; _ < 100000; _++){nonsense += 1;#ifdef FULLLOGstd::cout << "test" << endl;#endif#if falsecout <<"tes" << endl;#endifif(false){printf("Test");}}if (clock_gettime(CLOCK_MONOTONIC, &ts_sec)) { std::cout << "Error reading the time" << std::endl; }auto ts_sec_long = (long long) ts_sec.tv_sec * 1000000000 + (long long) ts_sec.tv_nsec;cout << "nonsense is " << nonsense << endl;cout << "Time spend with if(false) is " << ts_sec_long - ts_now_long << endl;if (clock_gettime(CLOCK_MONOTONIC, &ts_now)) { std::cout << "Error reading the time" << std::endl; }ts_now_long = (long long) ts_now.tv_sec * 1000000000 + (long long) ts_now.tv_nsec;int nonsense2 = 0;//submit the orderfor(auto _ = 0; _ < 100000; _++){nonsense2 += 1;}if (clock_gettime(CLOCK_MONOTONIC, &ts_sec)) { std::cout << "Error reading the time" << std::endl; }ts_sec_long = (long long) ts_sec.tv_sec * 1000000000 + (long long) ts_sec.tv_nsec;cout << "Time spend is with empty while loop " << ts_sec_long - ts_now_long << endl;cout << "nonsense is " << nonsense << endl;}
