1. Does anyone know...

If the amount of comments in a Euphoria program slows down execution at
all?  I know it does in other interpreted languages, but I haven't seen it
specifically stated for Euphoria (unless I missed it in the manual, I
looked, though...=)  I like to comment my source code.

Michael Packard
Lord Generic Productions
lgp at exo.com http://exo.com/~lgp
A Crash Course in Game Design and Production
http://exo.com/~lgp/euphoria

new topic     » topic index » view message » categorize

2. Does anyone know...

Michael Packard asks:
> If the amount of comments in a Euphoria program slows down execution at
> all?  I know it does in other interpreted languages, but I haven't seen it
> specifically stated for Euphoria (unless I missed it in the manual, I
> looked, though...=)  I like to comment my source code.

In refman.doc it states:
"Comments are ignored by the compiler
and have no effect on execution speed."

Feel free to add as many comments as you like.
They have no effect on speed since Euphoria converts
your source into an efficient internal representation
the first time it reads it from disk. Comments are discarded.
The internal representation is then executed.
(It's true that some BASIC interpreters
are slowed down a bit by comments.)

In Euphoria the only possible effect they might have is to slow down the
initial start-up or load time of a source .ex program by a few milliseconds,
but I doubt you could even measure it, and of course when you bind or shroud
a program all of the comments are stripped out anyway, so they can't
even affect the start-up time.

If you are concerned about getting a few more percent of
execution speed out of your program, a simple thing to
do is to make sure you take out all "with trace" and
"with profile" statements, and put a "without type_check"
statement at the top of your main .ex file, *before* any
include statements. graphics.e and others have user-defined
types that will be executed unless you say "without type_check"
at the very beginning, before you include them.

I recently noticed that in Jacques' Sound Blaster
code there were a few "with trace" statements left in the code.
This is innocent enough, but it will slow down his code and
any code that includes his .e files, by maybe 10%. The reason is
that an extra bit of executable code is inserted into the internal
representation of *every* traceable Euphoria statement.

I have since removed the "with trace" statements and put a new
version of his Sound Blaster stuff on the Euphoria WEB page
(plus a new version of Peter Blue's Space Invaders that was
including Jacques' files.)

Regards,
  Rob Craig
  Rapid Deployment Software

new topic     » goto parent     » topic index » view message » categorize

3. Re: Does anyone know...

I have seen no evidence that comments in Euphoria source lead to slower
programs. Whenever I finish my work and do not plan to add any more code
to the program, I start adding comments. This way, I will not forget what
I did when I come back to it. When I recompile my program, the program
appears to run the same speed. Mind you, the projects that I do tend to be
small to medium sized. Maybe it affects larger projects?

David Gay
http://www.interlog.com/~moggie/euphoria.htm

new topic     » goto parent     » topic index » view message » categorize

4. Re: Does anyone know...

Michael Packard writes:
> If I have the without type_check after the include files, will it slow the
> execution of those routines when they are called?  Or is it only slowed on
> loading initially?

with/without type_check does not affect loading time.

If you have the include statements first, followed by "without type_check"
then the routines in the included files will execute slower,
although the rest of your code will be fast.

For example, some of the routines in graphics.e have parameters that are
declared with user-defined types. Whenever a call is made to one
of these routines, Euphoria will check each argument value by calling the
appropriate type function.  e.g.

type color(integer x)
    return x >= 0 and x <= 255
end type

type mixture(sequence s)
    return length(s) = 3 -- {red, green, blue}
end type

global function palette(color c, mixture s)

Whenever you call palette(), Euphoria will also call color() and mixture()
*unless* the type_check option was turned off before palette() was defined.
If you say "without type_check" *before* "include graphics.e" then
Euphoria will not call color() or mixture(), so you could pass weird
values for c or s and it wouldn't be caught. If you passed a length-4
sequence for the mixture s, I believe it would quietly use the first 3 elements
for red/green/blue and not give any error message, even though there
would clearly be something wrong with your program. If you passed a bogus
color value like -1 or 1000, I suspect it would quietly do nothing.

Now, just to really confuse you...
Even with type checking turned off, Euphoria will still
do some very simple, very fast checks. In the above example,
Euphoria will make sure that c is an integer and s is a sequence,
but it won't do any more than that, i.e. it won't call the type
functions. By doing these simple type-checks whenever a variable is written,
Euphoria can avoid similar type-checks each time the variable is read.
Variables are usually read more often than they are written.


Regards,
  Rob Craig
  Rapid Deployment Software

new topic     » goto parent     » topic index » view message » categorize

5. Re: Does anyone know...

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 message » categorize

6. Re: Does anyone know...

thanx.

Michael Packard
Lord Generic Productions
lgp at exo.com http://exo.com/~lgp
A Crash Course in Game Design and Production
http://exo.com/~lgp/euphoria

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu