i am not sure how a function that will read the Intelx86 Time stamp counter would look like. i'm trying to measure the performance of a single function so I assume that I would need 2 functions:
1 - void startFunctionCounter(int *cycleval)
2 - void endFunctionCounter(int *cycleval)
I referred to this SO question Using Time stamp counter to get the time stamp and __rdtsc()
is mentioned. However I am not very familiar with asm and am not sure how 2 functions should look like. How should I adapt the code from the post I have linked to make it what I need?
Could someone tell me how this should be done? Appreciate any help. Thank you in advance! :)
edit: from reading the article linked, I have done something like this but I am getting a error message when compiling:
#include <stdio.h>
#include <stdint.h>
#include <intrin.h>
#include <x86intrin.h>
inline uint64_t readTSC() {
uint64_t tsc = __rdtsc();
return tsc;
}
void main(){
double initTSC = readTSC(), finalTSC= 0;
double array[5] = {5,6,4.6,1};
double x=6.0;
long deg = 3;
double res = calcFun(array,x,deg);
printf("hello there %f \n", res);
finalTSC = readTSC();
printf("hello timings \n 1: %f \n 2: %f", initTSC, finalTSC);
}
The error is :
/usr/lib/gcc/x86_64-pc-cygwin/10/../../../../x86_64-pc-cygwin/bin/ld: /tmp/ccqnytar.o:opt_poly.c:(.text+0x3f6): undefined reference to `readTSC'
I am using GCC compiler and C language.