On Mon, 27 Sep 1999, S.D.Mechveliani wrote:
> Now it shows the ratio * 6 *.
[snip]
> But this mess with platforms and versions, is not, probably, so
> important, because people can compile and run this program in their
> own environments - and correct the performance result.
>
> What do you think of it?
One small comment is that in your functions condition1 & condition2 I
think most C++ programmers would say that you want to write
int condition1 (const vector<long>& x)
since otherwise the compiler generally has to obey the normal function
call semantics and create a copy of the vector when it passes it the
function, rather than work directly with the existing list. Personally I'd
always write the above, not so much for performance reasons as the fact
that if the objects in the vector have a shallow copy constructor
(generated automatically & silently) but a destructor that deallocates
resources you've got an awful mess to debug when it crashes after leaving
the function; consequently I do this even when it isn't strictly
necessary. The few other C++ programmers I know do the same thing so
it's probably reasonable to assume everyone does.
An informal test on my machine reveals that this copying has a significant
effect even for such short vectors (51.5 odd user seconds for orig
version, 19.3 odd user seconds for new version, sys time <0.5 s in each
case but bear in mind no other special precautions taken, compiled on an
SGI O2 using SGI CC with no optimization) Unfortunately I don't have ghc
compiled on my system, so I'll leave the detailled comparison to others.
> -- C++ -------------------------------------------------------------
[snip]
> int condition1 (vector<long> x)
> {int i = 0;
> while (i < 10 & x[i] < 10) i++;
> return (i > 9);
> }
> int condition2 (vector<long> x)
> {int i = 0;
> while ( i < 20 & x[i]==9-i ) i++;
> return (i > 9);
> }
PS: I was one of the people who `criticised' Haskell for intensive
calculations and was asked to back this up. I'm working on getting a C++
and Haskell program doing the same thing that people in the know can
compare, but because what I'm arguing is that it's programs with
significant differences between `mathematical algorithm formulation' and
`computer language algorithm formulation' which would benefit most, the
examples are necessarily not tiny code fragments. I'll try and post
something later in the week but there are very pressing demands on my time
at the moment.
___cheers,_dave______________________________________________________
email: [EMAIL PROTECTED] "He'd stay up all night inventing an
www.cs.bris.ac.uk/~tweed/pi.htm alarm clock to ensure he woke early
work tel: (0117) 954-5253 the next morning"-- Terry Pratchett