View previous topic :: View next topic
|
Author |
Message |
Pankaj Shrivastava Currently Banned New User
Joined: 24 Jul 2009 Posts: 51 Location: Pune
|
|
|
|
Hi ,
I have a situation , where i need to execute a routine only for the first record of the file , and for susequent records I should not execute the routine . I saw/practiced the basic way of doing this is to set a flag 'N' After the first execution and check each time the value of this flag for 'Y' to determine if it has to be executed or not .
Code: |
CLI FLAG,'Y'
BNE SKIP
MVI FLAG,'N'
ROUTINE EQU *
...
...
SKIP EQU *
...
...
FLAG DC C'Y'
|
Is there any smarter way of doing this . Please help |
|
Back to top |
|
|
prino
Senior Member
Joined: 07 Feb 2009 Posts: 1315 Location: Vilnius, Lithuania
|
|
|
|
Why?
Is this method using to many yoctoseconds or not obfuscated enough? |
|
Back to top |
|
|
Pankaj Shrivastava Currently Banned New User
Joined: 24 Jul 2009 Posts: 51 Location: Pune
|
|
|
|
Robert,
My Program is reading more than 36 million records , this certainly is consuming some time checking the CLI each time .
I cant close the file after first record to reset the pointer in file . |
|
Back to top |
|
|
prino
Senior Member
Joined: 07 Feb 2009 Posts: 1315 Location: Vilnius, Lithuania
|
|
|
|
Pankaj Shrivastava wrote: |
My Program is reading more than 36 million records , this certainly is consuming some time checking the CLI each time . |
Are you effing serious?
The following PL/I code:
Code: |
dcl i fixed bin (31);
dcl j fixed bin (31);
j = random() * 10000000;
put skip data(j);
put skip list(datetime());
do i = 1 to 10000000;
if i = j then
put skip data(i);
end;
put skip list(datetime()); |
Results in this output, punctuation added to the timestamps for clarity:
Code: |
J= 4427071;
2009-07-27T10:23:54.294
I= 4427071;
2009-07-27T10:23:54.346
|
In other words, this whole loop took 52 milliseconds in a compiled language. |
|
Back to top |
|
|
Pankaj Shrivastava Currently Banned New User
Joined: 24 Jul 2009 Posts: 51 Location: Pune
|
|
|
|
Thx Robert , I appreciate your calculation . But i was looking for an answer not your justification of sparing 52 millisecond . If you dont know an alternative ..better not jump to write any thing rediculous . |
|
Back to top |
|
|
prino
Senior Member
Joined: 07 Feb 2009 Posts: 1315 Location: Vilnius, Lithuania
|
|
|
|
Pankaj Shrivastava wrote: |
I appreciate your calculation . But i was looking for an answer not your justification of sparing 52 millisecond . If you dont know an alternative ..better not jump to write any thing rediculous . |
My code showed that running this loop 10,000,000 times takes all of 52 milliseconds, so the kind of test will take about 5.2 nano-seconds. Assuming that your test will take about the same time, it will take less than .2 seconds of the total processing time for your 36,000,000 records, and the time to do so will be several orders of magnitude in excess of those 0.2 seconds.
The "CLI/BNE" code is readable and as fast as it possibly can be. |
|
Back to top |
|
|
Pankaj Shrivastava Currently Banned New User
Joined: 24 Jul 2009 Posts: 51 Location: Pune
|
|
|
|
Why your are struck in calculation of millisecond or so..i agree that it will hardly matter in one run or two .
Looking forward for someone to provide me an innovative solution ... |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
You can't get much faster than a CLI (an SI instruction), as the operand is part of the instruction and I don't really see an overhead issue at all.
You may want to look at a conditional NOP and that might give you back some time, although it will be minimal in the grand scheme of things.
You could try using SI instruction TM (it might be slightly faster, although that's a relative term), where the first time through, the target label is X'80' and then it is reset to X'00'. So, you'd have two different condition-codes: BO for the first TM X'80' (reset to X'00') and BZ for all other times (High-Bit is Off).
Bill |
|
Back to top |
|
|
Garry Carroll
Senior Member
Joined: 08 May 2006 Posts: 1205 Location: Dublin, Ireland
|
|
|
|
Pankaj,
Theres is a way. Some sites don't like self-modifying code, but this sample would do the trick.....
Code: |
CHGME NOP SKIPIT
MVI CHGME+1,X'F0'
ROUTINE EQU *
.
.
.
.
.
.
SKIPIT EQU * |
Basically, what's being done is to change a NOP instruction to a branch. The first time through, the NOP does nothing,the next instruction changes the NOP to a branch and the code in ROUTINE gets executed. Next time(s) through, the instruction at CHGME is a branch around ROUTINE.
Sometimes it's nice just to know that you can do these things....
Garry. |
|
Back to top |
|
|
Pankaj Shrivastava Currently Banned New User
Joined: 24 Jul 2009 Posts: 51 Location: Pune
|
|
|
|
I wrote a simple program ..wherein i tried to avoid using any conditional check to determine the execution of a routine :
Code: |
PGMXYZ START 0
BALR 3,0
USING *,3
ST 14,MYVAR
LH 7,=H'10'
LA 6,FIRSTIME
B CNTR
LOOP BR 6
FIRSTIME EQU *
LA 6,OTHRTIME
WTO 'FIRSTTIME'
B CNTR
OTHRTIME EQU *
WTO 'OTHERTIME'
CNTR BCT 7,LOOP
SKIP L 14,MYVAR
BR 14
FLAG DC C'Y'
MYVAR DS F
END
|
Here rather then using CLI i am using BR ..and the dseired address ( first or subsequent ) has been put in place.
Please comment if this code has any glitch ..though it lloks as if it may work better than conditional one .
Thanks |
|
Back to top |
|
|
Pankaj Shrivastava Currently Banned New User
Joined: 24 Jul 2009 Posts: 51 Location: Pune
|
|
|
|
Thanks a lot !! The NOP is really a fentastic way !!
Thanks ..i will keep your suggestion |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10888 Location: italy
|
|
|
|
using a nop will make the program not reentrant,
many audit/review processes will reject the code |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
Quote: |
I have a situation , where i need to execute a routine only for the first record of the file , and for susequent records I should not execute the routine |
Why not have the first record read, execute your routine, then start a loop to read the rest of the records? Sure there's two read statements but there's no testing overhead at all.
Of course, as was pointed out, you are spending WAY too much time and effort worrying about fractions of a second. You want to optimize something that does not need optimizing anyway. If your program was having performance problems (such as not completing within the batch window), I'd say you might want to think about this. If it is completing within the expected time frame, though, you're just wasting resources looking at this. |
|
Back to top |
|
|
|