Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Optimal code to check the efficiency

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> PL/I & Assembler
View previous topic :: :: View next topic  
Author Message
prino

Active Member


Joined: 07 Feb 2009
Posts: 982
Location: Oostende, Belgium

PostPosted: Fri Jan 15, 2016 12:05 am    Post subject: Optimal code to check the efficiency
Reply with quote

I've got a bit of code that adds CHAR(4) variables (up to a maximum of around 200) as CHAR(5) (i.e appended with a blank) in alphabetic order to a CHAR (1022) VAR.

The code I now use is:

Code:
dcl c   char       (4);
dcl cs  char    (1022) var;
dcl tcn char       (5);
dcl #c  fixed bin (31);
dcl #i  fixed bin (31);

tcn = c;

if index(cs, c) = 0 then
  do;
    #c = #c + 1;

    do #i = 1 to length(cs) by 5 while(substr(cs, #i, 4) < c);
    end;

    cs = substr(cs, 1, #i - 1) || tcn || substr(cs, #i);
  end;

but having been bitten by this use of index() before in a really, Really, REALLY bad way, the following seems to be far more efficient:

Code:
tcn = c;

do #i = 1 to length(cs) by 5 while(substr(cs, #i, 5) < tcn);
end;

if substr(cs, #i, 5) ^= tcn then
  do;
    #c = #c + 1;
    cs = substr(cs, 1, #i - 1) || tcn || substr(cs, #i);
  end;

but of course running this with the "COUNT/FLOW" option of the V2.3.0 OS Compiler leads to statement counts that are significantly higher due to the fact that the "do #i" loop in now always executed, be it that it's far more efficient than the old "index()", as that only checks on a character-by-character basis.

Does anyone have any smart method, without having to actually print assembler listings and count the actual number of assembler statements executed, to check the efficiency of both approaches. I'm sure doing this lots of times in a loop (I can provide the currently 4,321 actual values of "c" (33 different ones) that are pumped into the routine) and timing it with Strobe would undoubtedly provide a clear winner, but sadly I don't have access to Strobe.
Back to top
View user's profile Send private message

KimTyson

New User


Joined: 11 Feb 2016
Posts: 1
Location: Canada

PostPosted: Fri Feb 12, 2016 4:41 am    Post subject: Reply to: Optimal code to check the efficiency
Reply with quote

I'm not sure you can use the routine this way without seeing the whole program but it could be more efficient to add the variables to an array and then sort the array (deleting duplicates as you progress). A sink or bubble sort will do fine. Then assign the array variables remaining to your final "cs" string.

Another caution here is that some shops do not initialize all memory to 0 before your program loads so your counters (for example #c) could contain invalid starting values. As a best practices move I would initialize all variables to blank, 0 or a value via the init keyword in the compile. icon_smile.gif
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> PL/I & Assembler All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts What is the code in CLIST to enable t... jackzhang75 CLIST & REXX 1 Fri Dec 02, 2016 3:02 am
No new posts IDEAL - Code Retrieval yugendran CA Products 0 Fri Nov 25, 2016 3:27 pm
No new posts What is the command to check MODE of ... rohanthengal CLIST & REXX 6 Fri Nov 18, 2016 1:48 pm
No new posts Check System time(Minute) Using TIME1... balaji81_k DFSORT/ICETOOL 5 Fri Nov 11, 2016 10:53 am
This topic is locked: you cannot edit posts or make replies. Need to code a Rexx PGM sundaram.naveen CLIST & REXX 18 Thu Oct 06, 2016 6:45 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us