Guidance
指路人
g.yi.org
Guidance Forums / Reginald Rexx / Speed

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
Forum List • Thread List • Refresh • New Topic • Search • Previous • Next First 1 Last
Message1. Speed
#1303
Posted by: guidance 2002-11-07 16:48:25
The main reason I decided to learn Rexx and use Reginald is the amazing execution speed, compared with other script languages.
I tried a simple loop:
s=0
DO i=0 TO 100000
  s=s+i
END
SAY s
The speed of Reginald is really impressive! Jeff, How can you reach this? Do you do any optimization for speed? Are there any intermediate codes, such as byte code like Java, of the source script? And what should we, as Reginald users, do or not do to avoid conflict with these optimizations?

By the way, is there a REXX equivalent to the C language's ++/-- operators?
Message2. Re: Speed
#1304
Posted by: 2002-11-07 23:28:26
It's just plain interpreted text -- no byte codes. In the case of variables, sometimes structures associated with them are cached so that the interpreter doesn't have to look through the entire table of variable names, and that can speed up run time a bit. Since REXX is a "simpler language" than some other interpreted languages like Java, it can be a bit more stream-lined, and therefore faster. Java has to support the whole concept of "objects" so there is an entire complex datatype inflicted upon the entire interpreter.

There is no ++/-- operator. You increment/decrement a numeric variable by adding/subtracting 1 to it as so:
myvar = myvar + 1
There is one speed improvement I sometimes make. If I've got a numeric integer (no decimal point) variable, and I know that it's value is less than the NUMERIC DIGITS setting (so it isn't going to need to be rounded), and I need to test if it is a particular value, I'll use a strict comparison (instead of normal comparison). For example, consider the following two lines:
IF i = 1 THEN SAY "i = 1"
IF i == 1 THEN SAY "i = 1"
The second one is faster because '1' is treated as a literal string that just happens to consist of an ascii numeric character. (Remember that all numbers are really strings in REXX) In the first instruction, both "1" and "i" are stripped of spaces, and then they are checked to make sure that they are rounded to the current NUMERIC DIGITS settings (and if they were expressed in exponential form, then they are converted to "normal" notation with a decimal point), and if they have a fractional part (ie, a decimal point and numbers to the right of it), then any trailing zeros on the fractional part are accounted for in the comparison.

But if you're dealing with simple integers, then that's extra overhead that isn't really needed (because no rounding needs to be done, the numbers aren't in exponential form, and there are no trailing zeros on any decimal part). So the strict comparison is faster.

But an example of where you can get into problems with this speedup is if you try it with non-integer values, or ones that exceed NUMERIC DIGITS setting, or have embedded spaces, for example:
myvar = 1.0

IF myvar = 1 THEN SAY "First test is true"
ELSE SAY "First test is false"

IF myvar == 1 THEN SAY "Second test is true"
ELSE SAY "Second test is false"
The above displays:

First test is true.
Second test is false.

After all 1.0 is the same as 1. But when you do a strict comparison, then they are not the same (because one has a decimal point and an extra 0).

So too, spaces can be a problem:
myvar = ' 1 '

IF myvar = 1 THEN SAY "First test is true"
ELSE SAY "First test is false"

IF myvar == 1 THEN SAY "Second test is true"
ELSE SAY "Second test is false"
The above displays:

First test is true.
Second test is false.

That's because MyVar has embedded spaces. These are not trimmed off in a strict comparison.
Forum List • Thread List • Refresh • New Topic • Search • Previous • Next First 1 Last
掌柜推荐
 
 
 
 
 
 
 
 
 
 
 
 
© Sat 2024-10-5  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0