Re: Robert faster?

new topic     » goto parent     » topic index » view thread      » older message » newer message

Lucius Hilley writes:
> Which would be better?

> integer width, height
> sequence s

> width =3D 5
> height =3D 10
> faster =3D 1 -- should faster =3D 1 or 0?
> if faster then
>   s =3D repeat(repeat(0, width), height)
> else
>   s =3D repeat(height) =

> end if
> for a =3D 1 to height do
>   s[a] =3D {a, a + 1, a + 2, a + 3, a + 4}
> end for

Instead of: repeat(height) - I assume you mean: repeat(0, height).

I haven't timed it, but I'm pretty sure the "repeat(0, height)"
method would be faster, i.e. faster =3D 0.

When I want to time a small section of code like this, I do the
following:

atom t
t =3D time()
for i =3D 1 to 1000 do
   ... section of code ...
end for
? time() - t =


If it takes less than a few seconds I increase
the "1000" and run it again. (Of course in some cases
1000 would be too large to start with.)

Then I modify "section of code" and run it again
and compare the times.

Perfectionists might also time the for-loop with
an *empty* body, so they can deduct the time overhead
contributed by the loop mechanism - i.e. incrementing =

the loop variable, comparing against the limit, etc. =

This is only useful if your section of code takes
very little time.
 =

Regards,
  Rob Craig
  Rapid Deployment Software

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu