Re: Does anyone know...

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

Michael Packard writes:

> oh.  That makes sense, sorta.  Now, is there a speed difference between
> having sequences vs objects?  I vaguely remember a discussion on this
> awhile back, but I can't remember.  I usually have my animation frames
> stored as objects (when they are really sequences of sequences) to
> distinguish them from my arrays, which are sequences.  If it's slower to
> do this way I'll go back to sequences for everything...

Personally, I like to declare things as sequences,
unless I want to sometimes assign an atom value to them.
This provides a bit of extra error checking, and usually a bit
of speed as well. Here's why:

If you have:
   sequence s
then
   s[i]
will be evaluated maybe 5% faster because Euphoria will
"know" that s must have a sequence value, and will not
have to confirm this each time before subscripting it.
(It will translate your source into a slightly different
internal representation that does not perform this check.)
If s were declared as an object then a run-time check
would be required, since you can't subscript an atom value.

However assignments to s might be slower
if Euphoria needs a run-time check to see if
you've really assigned a sequence value to s or not.
Usually, no run-time check is actually required. For example
if s and t are declared as sequences,

   s = t              -- no check, we know t must be a sequence
   s = repeat(a, b)   -- no check, we know repeat() always returns a sequence
   s = gets(0)        -- have to check, gets() sometimes returns -1

Since you probably evaluate s[i] many more times than you assign to s,
you will probably gain a tiny bit of speed by declaring s as a sequence
rather than an object. Of course there is probably lots of other
stuff going on in your program, so the effect will be diluted.

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