Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist 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

Senior Member


Joined: 07 Feb 2009
Posts: 1059
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 Speed-up/reduce CPU use of code prino PL/I & Assembler 0 Tue Sep 26, 2017 12:05 am
No new posts ALPHABETIC check in COBOL vidyaa COBOL Programming 8 Thu Aug 17, 2017 7:13 pm
This topic is locked: you cannot edit posts or make replies. how to code for GDG in Rexx cvnlynn CLIST & REXX 13 Wed Aug 09, 2017 9:13 pm
This topic is locked: you cannot edit posts or make replies. rexx code to create a ps file Bharath Vikraman CLIST & REXX 4 Mon Aug 07, 2017 10:30 am
No new posts I want to retire TRX and use only Rex... Abhinav Sharma CLIST & REXX 6 Sat Jul 29, 2017 2:53 am

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us