I have a question about the performance of my code. Let them say that I have a structure in C for the point:
typedef struct _CPoint { float x, y; } CPoint;
and a function in which I use struct.
float distance(CPoint p1, CPoint p2) { return sqrt(pow((p2.x-p1.x),2)+pow((p2.y-p1.y),2)); }
I was wondering if it would be a smart idea to replace this function with #define,
#define distance(p1, p2)(sqrt(pow((p2.x-p1.x),2)+pow((p2.y-p1.y),2)));
I think it will be faster because there will be no overhead, and I am wondering if I should use this approach for all other functions of my program in order to increase productivity. So my question is:
Should I replace all my functions with #define to improve the performance of my code?
source share