On 28-Sep-1999, S.D.Mechveliani <[EMAIL PROTECTED]> wrote:
> D. Tweed <[EMAIL PROTECTED]> writes
> T> One small comment is that in your functions condition1 & condition2 I
> T> think most C++ programmers would say that you want to write
> T>
> T> int condition1 (const vector<long>& x)
> T>
> T> since otherwise the compiler generally has to obey the normal function
> T> call semantics and create a copy of the vector when it passes it the
> T> function, rather than work directly with the existing list.
>
> Thank you.
> Here is again the improved test.
...
> And now the performance ratio shows * 16 *.
>
> I understand this so, that this particular task allows to set
> `const'. Because first, condition1, condition2 apply to the
> vector x; as they do not modify x, next_permutation(x)
> yields the correct value when applied after them.
>
> Probably, other tasks and `condition1' variants would not allow to
> set `const' like here.
> Do i understand right?
> And for these cases the ratio is smaller, say, 6, as showed the
> earlier test - ?
No. `const' here probably has no effect on the efficiency.
The difference in efficiency is due to the copying, which is
because your original C++ program unwisely used pass-by-value,
rather than pass-by-const-reference. Most likely pass-by-reference
and pass-by-const-reference will have exactly the same performance.
--
Fergus Henderson <[EMAIL PROTECTED]> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger [EMAIL PROTECTED] | -- the last words of T. S. Garp.