@dtech said:
@dtech said:Solution: write a benchmark demonstrating both "optimization" steps and see if they actually do anything.
here you go. Note: It's been years since I last touched C and I never had any real experience with it.
In the few runs I did the differences were in the milliseconds (with 1 millions executions). The struct was generally faster
FTFY
A sample run with 20billion iterations and compiled with -O2 in gcc:
41.680000 - no parameters (control)
81.810000 - struct byref ordered
83.140000 - struct byref unordered
115.290000 - struct byval ordered
121.620000 - struct byval unordered
71.760000 - separate params ordered
71.110000 - separate params unordered
I'm not sure I trust that the ordered/unordered differences are above the noise floor, but I think I've got the compiler to do a semi-useful comparison between the byref/byval/params.
Conclusion: there can be a difference. It's negligible.
I, for one, am going to continue passing structs (because they're pretty important for writing maintainable code) by reference (because passing by value doesn't help).