I'm running a simulation which takes some time to run and I want to improve that. From what I understood, passing a value to a function means that that value is copied which is slow. Is there a way to include some functions in a dedicated file where I won't need to copy the values?
I don't mind to do "Wrong programing" (global variable, public access etc.) to gain speed.
Thanks
Edit: when I started my project, I tested several loops. I counted processor style between the start and the stop of a loop of that kind:
int i = 0;
while (i < 10000000){
i = doStuff(i); //or doStuff();
}
int doStuff(i){
return i++;
}
int doStuff(){
return i++;
}
I'm pretty sure that the doStuff() case was 10 times faster. I have changed my previous code to global variables and direct access ("wrong programming") and it improved my runtime significantly. I tried to use references but I had some inherent problem which prevented me from doing so (I don't remember what it was). Anyhow, I'm playing around with gprof now.