Click here to Skip to main content
15,891,316 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hello!

Which code is the fastest?

this one:

C++
typedef struct tagDATA {
   int value;
} DATA, *LPDATA;

void foo(LPDATA data, int value) {
   doSomething(value);
}


or:

C++
typedef struct tagDATA {
   int value;
} DATA, *LPDATA;

void foo(LPDATA data) {
   doSomething(data->value);
}


Thank you for any answer :)

What I have tried:

I have implemented these two codes but i want to know if a method is fastest than the other.
Posted
Updated 28-Feb-16 2:16am
Comments
Arthur V. Ratz 20-Mar-16 11:31am    
you can measure the real execution time by using clock() function before and after the code execution.

1 solution

First of all - why not run tests of your own or using some tools???

There is no measurable difference between the two, in both cases the pointer to value has to be resolved, the only difference is that in the first case the resolving done outside the function (not in your sample) and in the second case it is done inside the function...
The only difference in performance can be caused by passing unneeded parameter (LPDATA data) in the first case...Pushing that data to the stack may cause a performance issues in some cases...
 
Share this answer
 
Comments
Arthur V. Ratz 21-Mar-16 2:18am    
5.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900