Actually, (at least in UniData) it is a performance improvement :). It
has to do with how BASIC compiles the code into the object file and tags
each line with a line number. Each time it jumps to a line or progresses
to the next it must process the line number to update it for when it
shows errors/warnings etc. By reducing the number of lines the
instructions are on, you actually end up with both smaller object code
and faster execution.

How much though depends on how tight your looping and all but 99%+ cases
the difference is dwarfed by disk access times, etc as to make it not
worth it as a human optimisation task.


-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Gregor Scott
Sent: Thursday, 3 March 2011 4:16 PM
To: U2 Users List
Subject: Re: [U2] Is this worth rewriting?

The other thing to try, though not really a performance improvement, is
the following:

Replace:

  IF P7.100<CM> = '' THEN
    CUMO(M) += P12.101<CM>
  END ELSE
    CUMO(M) += P7.100<CM>
  END

  IF P7.101<CM> = '' THEN
    CUMO(M) += P12.133<CM>
  END ELSE
    CUMO(M) += P7.101<CM>
  END

  IF P7.102<CM> = '' THEN
    CUMO(M) += P12.134<CM>
  END ELSE
    CUMO(M) += P7.102<CM>
  END

with

  CUMO(M) += (IF P7.100<CM> = '' THEN P12.101<CM> ELSE P7.100<CM>)
  CUMO(M) += (IF P7.101<CM> = '' THEN P12.133<CM> ELSE P7.101<CM>)
  CUMO(M) += (IF P7.102<CM> = '' THEN P12.134<CM> ELSE P7.102<CM>)



Gregor

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Gregor Scott
Sent: Thursday, 3 March 2011 3:13 PM
To: U2 Users List
Subject: Re: [U2] Is this worth rewriting?

A suggestion: Raise the @VM to @AM to improve dynamic array performance.
Attribute lookups are way faster than value lookups, and you have
already extracted the data to a new variable

MONTHLY.USAGE:

CM = MONTH + LY.CNT

P12.101 = RAISE(PARMS(12)<101>)
P12.133 = RAISE(PARMS(12)<133>)
P12.134 = RAISE(PARMS(12)<134>)

P7.100  = RAISE(PARMS(7)<100>)
P7.101  = RAISE(PARMS(7)<101>)
P7.102  = RAISE(PARMS(7)<102>)

FOR M = 1 TO 12

  CUMO(M) = P12.101<CM> + P12.133<CM> + P12.134<CM>

  IF P7.100<CM> = '' THEN
    CUMO(M) += P12.101<CM>
  END ELSE
    CUMO(M) += P7.100<CM>
  END

  IF P7.101<CM> = '' THEN
    CUMO(M) += P12.133<CM>
  END ELSE
    CUMO(M) += P7.101<CM>
  END

  IF P7.102<CM> = '' THEN
    CUMO(M) += P12.134<CM>
  END ELSE
    CUMO(M) += P7.102<CM>
  END

NEXT M

RETURN

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Allen E.
Elwood
Sent: Thursday, 3 March 2011 2:22 PM
To: 'U2 Users List'
Subject: Re: [U2] Is this worth rewriting?


All right, I just went ahead and rewrote this the way I would do it
since I haven't written a single bit of code since I got laid off at the
end of September.  And I did it while my wife and I are watching Judge
Judy - it was *fun* :-)

Granted I can't use real var names since I don't know what these are,
but using a simple var name replacement scheme, this illustrates what I
would consider the least amount of overhead for this.

A) reduced the overhead on the repetitive calls to over 100 attrs.  The
system needs to look at *every single byte* in the record until it gets
to attr desired.  If these are 25,000 byte records this would be a HUGE
amount of needless throughput which you can calc by (iterations - 2) *
average bytes to read before attr needed * number of times the statement
is used in the loop

B) Yup, got rid of the #.  Not only does this make more sense, but # is
REALLY doing two comparisons: < and >

C) Got rid of the leading 7 digit indent to make it more readable

D) I don't see the necessity of testing three vars to see if they aren't
zero before adding them together.  If they are zero, the equation will
work.
If they are not zero, the equation will work.  I can see maybe doing
that if the equation was doing any dividing to avoid the "can't divide
by zero"
error, but not on adding.

E) I always make all my IF's block IF's to stub them out for future dev,
as well as to make them easier to read.  So I did that at the bottom
even though it was just for one add stmt.

F) My eyes are really getting old.  I need spaces between VARs and
operands so they don't smush together.  So I spaced accordingly to make
everything just a tad more readable as well.

Now, this takes more lines of code.  But many times more lines of code
can be way faster than fewer lines of code especially if the extra lines
of code are OUTSIDE of the loop.

MONTHLY.USAGE:

CM = MONTH + LY.CNT

P12.101 = PARMS(12)<101>
P12.133 = PARMS(12)<133>
P12.134 = PARMS(12)<134>

P7.100  = PARMS(7)<100>
P7.101  = PARMS(7)<101>
P7.102  = PARMS(7)<102>

FOR M = 1 TO 12

  CUM(M) = P12.101<1,CM> + P12.133<1,CM> + P12.134<1,CM>

  IF P7.100<1,CM> = '' THEN
    CUMO(M) += P12.101<1,CM>
  END ELSE
    CUMO(M) += P7.100<1,CM>
  END

  IF P7.101<1,CM> = '' THEN
    CUMO(M) += P12.133<1,CM>
  END ELSE
    CUMO(M) += P7.101<1,CM>
  END


  IF P7.102<1,CM> = '' THEN
    CUMO(M) += P12.134<1,CM>
  END ELSE
    CUMO(M) += P7.102<1,CM>
  END

  CM -= 1

  IF CM = 0 THEN
    CM = 24
  END

NEXT M

PARMS(12)<101> = P12.101
PARMS(12)<133> = P12.133
PARMS(12)<134> = P12.134

PARMS(7)<100> = P7.100
PARMS(7)<101> = P7.101
PARMS(7)<102> = P7.102

RETURN

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Keith Johnson
[DATACOM]
Sent: Wednesday, March 02, 2011 4:47 PM
To: '[email protected]'
Subject: Re: [U2] Is this worth rewriting?

Agreed that the dimensioned extract wouldn't make much difference, still
the attributes numbers are quite high.

The code below goes from 15 extracts maximum per for-next loop to 6.
I can't help but think this might mean something if it takes 90 minutes
to run.

001: MONTHLY.USAGE:
002: CM = MONTH + LY.CNT
003: FOR M = 1 TO 12
004:   TEA = PARMS(12)<101,CM>
005:   EAT = PARMS(12)<133,CM>
006:   ATE = PARMS(12)<134,CM>
007:   IF TEA # '' OR EAT # '' OR ATE # '' THEN CUM(M) = TEA + EAT + ATE
008:   YAM = PARMS(7)<100,CM>
009:   AMY = PARMS(7)<101,CM>
010:   MYA = PARMS(7)<102,CM>
011:   IF YAM # '' OR AMY # '' OR MYA # '' THEN
012:     IF YAM # '' THEN CUMO(M) += YAM ELSE CUMO(M) += TEA
013:     IF AMY # '' THEN CUMO(M) += AMY ELSE CUMO(M) += EAT
014:     IF MYA # '' THEN CUMO(M) += MYA ELSE CUMO(M) += ATE
015:   END
016:   CM -= 1 ; IF CM = 0 THEN CM = 24
017: NEXT M
018: RETURN


So I'd say AYE - or YEA, if you use meaningful variables

Regards, Keith

_______________________________________________
U2-Users mailing list
[email protected]
http://listserver.u2ug.org/mailman/listinfo/u2-users

_______________________________________________
U2-Users mailing list
[email protected]
http://listserver.u2ug.org/mailman/listinfo/u2-users
--
Message  protected by DealerGuard: e-mail anti-virus, anti-spam and
content filtering.
http://www.pentanasolutions.com

Click here to report this message as spam:
https://login.mailguard.com.au/report/1BP6OgvpJo/5gVwRJ7D4CmnHzlAiSIy64/
0.6


This email and any attachments to it are confidential.
You must not use, disclose or act on the email if you are not the
intended recipient.  Liability limited by a scheme approved under
Professional Standards Legislation.
_______________________________________________
U2-Users mailing list
[email protected]
http://listserver.u2ug.org/mailman/listinfo/u2-users
--
Message  protected by DealerGuard: e-mail anti-virus, anti-spam and
content filtering.
http://www.pentanasolutions.com

Click here to report this message as spam:
https://login.mailguard.com.au/report/1BP7ILuqRE/6DUunh7G6IMaVHkICvfXx8/
0.6


This email and any attachments to it are confidential.
You must not use, disclose or act on the email if you are not the
intended recipient.  Liability limited by a scheme approved under
Professional Standards Legislation.
_______________________________________________
U2-Users mailing list
[email protected]
http://listserver.u2ug.org/mailman/listinfo/u2-users

______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email
______________________________________________________________________
###########################################################################################
The information transmitted in this message and attachments (if any) is 
intended only
for the person or entity to which it is addressed. The message may contain 
confidential
and/or privileged material.  Any review, retransmission, dissemination or other 
use of
or taking of any action in reliance upon this information by persons or 
entities other
than the intended recipient is prohibited.  If you received this in error, 
please
contact the sender and delete the material from any computer.

The intended recipient of this e-mail may only use, reproduce, disclose or 
distribute
the information contained in this e-mail and any attached files with the 
permission of IMB.
###########################################################################################
_______________________________________________
U2-Users mailing list
[email protected]
http://listserver.u2ug.org/mailman/listinfo/u2-users

Reply via email to