[comp.lang.rexx] MVS REXX, Rexx in general - efficiency questions

grimlok@hubcap.clemson.edu (grimlok) (06/20/89)

In an effort to learn Rexx and start a conversion of some very UGLY
Clists, I have been writing some of the less ugly smaller clists in
Rexx.                                    

Knowing that Rexx is interpreted, and knowing that our Reference manual
is backordered, I encountered a few questions of efficiency which I am
unable to answer.

Here are a few:
 
 1) Is copies(" ",80) any worse or better than copies("  ",40) or for
    that matter copies("    ",20)? The first is obvious that I want an
    80 character string consising of blanks, it gets less obvious as we
    go down. Probably the best thing is to set a variable to a constant
    like spaces = "    ...80 spaces..." but you have to split it up and
    it becomes unreadable and the chances of mis-counting are great.
    In short, how does copies() really work?
 
 2) Given that the comparision x = y will give me the same results
    as x == y for the possible values of x and y in my program, is one
    "better" than the other?
 
 3) Are logical operators short circuiting? That is, if I say:
    if x | y | z then ... and x is true, are y and z evaluated and or'd?
    If z is true 90% of the time and x and y only 20%, should I put
    if z | x | y then ... to save time, even though it is slightly less
    intuitive? I know from seeing select traced that when a when
    expression is true the other cases are bypassed. 

Thanks in advance.


-- 

'I just couldn't convince the voters that Dukakis was Greek for
"Bubba".' -- Lloyd Benson explaining why the Democrats didn't carry
Texas

patterso@hardees.rutgers.edu (Ross Patterson) (06/21/89)

> 1) Is copies(" ",80) any worse or better than copies("  ",40) or for
>    that matter copies("    ",20)? The first is obvious that I want an
>    80 character string consising of blanks, it gets less obvious as we
>    go down. Probably the best thing is to set a variable to a constant
>    like spaces = "    ...80 spaces..." but you have to split it up and
>    it becomes unreadable and the chances of mis-counting are great.
>    In short, how does copies() really work?

In my experience with CMS REXX, there is no significant difference between
the three examples you give. In any case, these things are typically only
executed once, whenn initializing a constant ("Bar = Copies('=',72))". Using
Copies is definitely better than hand typing a long, repetative constant, if
only for readability.
 
> 3) Are logical operators short circuiting? That is, if I say:
>    if x | y | z then ... and x is true, are y and z evaluated and or'd?
>    If z is true 90% of the time and x and y only 20%, should I put
>    if z | x | y then ... to save time, even though it is slightly less
>    intuitive? I know from seeing select traced that when a when
>    expression is true the other cases are bypassed.

I believe your real questionnn is whether REXX fully evaulates conditional
expressions, and the answer is yes. The entire IF, WHEN, DO UNTIL, or DO
WHILE condition is evaluated each time, regardless of predictability. This
is neither right nor wrong, it simply is. Each language designer makes a
decision as to what the sequence of evaluation will be, and whether the
compiler (or interpreter) guarantees that sequence. You won't see any
performance improvement by ordering your "if x | y | z" as "if z | x | y".

Ross Patterson
Rutgers University