why dont you actually go try to make it faster and then report your results instead of guessing inappropriate things.
]]>I believe what you mean is this: rules of thumb they always teach you in school aren't right, but here's one: passing things with costly copy constructors, or things larger than the machine word as reference might be faster.
If you believe that "if you always pass by reference instead of by value then the program will run faster" then simply scour the vast majority of c++ stuff in existence and you will discover that reference parameters are relatively infrequent except when dealing with bulky objects (to avoid copying) or templates.
It costs nothing to "copy" ints.
]]>#include <iostream>
#include <time.h>
using namespace std;
void pass_by_reference(const int& a, const int& b, const int& c)
{
}
void pass_by_const(const int a, const int b, const int c)
{
}
void pass_by_value(int a, int b, int c)
{
}
int main ()
{
time_t start,end;
double dif;
int a, b, c;
//reference
time (&start);
for(unsigned int i = 0; i < 4294967295; i++)
pass_by_reference(a, b, c);
time (&end);
dif = difftime (end,start);
cout << "Pass by reference: " << dif << endl;
//const
time (&start);
for(unsigned int i = 0; i < 4294967295; i++)
pass_by_const(a, b, c);
time (&end);
dif = difftime (end,start);
cout << "Pass by const: " << dif << endl;
//value
time (&start);
for(unsigned int i = 0; i < 4294967295; i++)
pass_by_value(a, b, c);
time (&end);
dif = difftime (end,start);
cout << "Pass by value: " << dif << endl;
return 0;
}
************************************************************
The output is usually 17 seconds for pass by reference, 26 for const and value, respectively.