IBM Mainframe Forum Index
Log In
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register

Optimal code to check the efficiency

IBM Mainframe Forums -> PL/I & Assembler
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Warnings : 1

Senior Member

Joined: 07 Feb 2009
Posts: 1241
Location: Vilnius, Lithuania

PostPosted: Fri Jan 15, 2016 12:05 am
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:

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
    #c = #c + 1;

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

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

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:

tcn = c;

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

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

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

New User

Joined: 11 Feb 2016
Posts: 1
Location: Canada

PostPosted: Fri Feb 12, 2016 4:41 am
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> PL/I & Assembler


Similar Topics
Topic Forum Replies
No new posts Numeric check w/SyncSort. SYNCSORT 1
No new posts Execute step regardless of previous s... JCL & VSAM 2
No new posts Error 0C1 Reason Code 1 with branch i... PL/I & Assembler 3
No new posts JCL for replacing code in Cobol JCL & VSAM 7
No new posts Easytrieve EZABX007 with error code 0... CA Products 7
Search our Forums:

Back to Top