我正在尝试测量并行端口上 2 个信号之间的时间差,但首先我要知道我的测量系统(AMD Athlon(tm) 64 X2 双核处理器 5200+ \xc3\x97 2) 在 SUSE 12.1 x64 上。
\n\n因此,经过一番阅读后,我决定使用clock_gettime(),首先我使用以下代码获取clock_getres()值:
\n\n/*\n * This program prints out the clock resolution.\n */\n#include <stdio.h>\n#include <stdlib.h>\n#include <time.h>\n\nint main( void )\n {\n struct timespec res;\n\n if ( clock_getres( CLOCK_REALTIME, &res) == -1 ) {\n perror( "clock get resolution" );\n return EXIT_FAILURE;\n }\n printf( "Resolution is %ld nano seconds.\\n",\n res.tv_nsec);\n return EXIT_SUCCESS;\n }\nRun Code Online (Sandbox Code Playgroud)\n\n结果是:1 纳秒。我很高兴!
\n\n但这是我的问题,当我尝试用其他代码检查这一事实时:
\n\n#include <iostream>\n#include <time.h>\nusing namespace std;\n\ntimespec diff(timespec start, timespec end);\n\nint …Run Code Online (Sandbox Code Playgroud)