I used the web editor ideone.com. I wrote the code shown below in C++. Using CLK_TCK, I attempted to measure the operation time of the function I defined (called "f1" in my code). As shown in below, in the "output" space of the web editor (maybe correspond to terminal in some editors), it said that CLK_TCK is undefined and it advised me to use CLOCK_TAI instead.
Would you please answer the following two questions regarding this?
Question1: Why is CLK_TCK undefined in my case?
Question2: What is the difference between CLK_TCK and CLOCK_TAI?
The code I wrote is shown below.
#include <stdio.h>
#include <time.h>
#include <math.h>
clock_t start, stop;
double duration;
#define MAXN 10
double f1 (int n, double a[], double x) {
int i;
double p=a[0];
for (i=1; i<=n; i++)
p+=(a[i]*pow(x,i));
return p;
}
int main() {
int i;
double a[MAXN];
for (i=0;i<MAXN;i++) a[i]=(double)i;
start=clock();
f1(MAXN-1,a,1.1);
stop=clock();
duration=((double)(stop-start))/CLK_TCK;
printf("ticks1 = %f\n", (double)(stop-start));
printf("durationa1=%6.2e\n",duration);
return 0;
}
The sentences shown in the output space in the web editor.
Compilation error #stdin compilation error #stdout 0s 5532KB
prog.cpp: In function ‘int main()’:
prog.cpp:29:34: error: ‘CLK_TCK’ was not declared in this scope
duration=((double)(stop-start))/CLK_TCK;
^~~~~~~
prog.cpp:29:34: note: suggested alternative: ‘CLOCK_TAI’
duration=((double)(stop-start))/CLK_TCK;
^~~~~~~
CLOCK_TAI