View previous topic :: View next topic |
Author |
Message |
tattva Beginner
Joined: 02 Feb 2005 Posts: 97 Topics: 36
|
Posted: Wed Feb 02, 2005 5:59 am Post subject: Improve Performance |
|
|
Hi all ,
i need to replace the below piece of code with a more efficient code in order to improve the system performance. let me know ur suggestions
PERFORM
VARYING index1 FROM 1 BY 1
UNTIL index1 > MAX-COUNT
IF CUST-NUM(index1)
= CUST-NUM(index2)
AND dia-num(index1)
>= '40000'
AND dia-num(index1)
<= '49999'
STATEMENTS...
......
END-PERFORM
this is consuming a lot of CPU time and needs to be tuned.
Could you guys help me out...
TIA
--------
tattva |
|
Back to top |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
|
Posted: Wed Feb 02, 2005 8:16 am Post subject: |
|
|
Tatva,
How are INDEX1 & INDEX2 defined?
Using indexes to address a table is more efficient than using subscripts since the index already contains the displacement from the start of the table and does not have to be calculated at run time. Subscripts, on the other hand, contain an occurrence number that must be converted to a displacement value at run time before it can be used. When using subscripts to address a table, use a binary (COMP) signed data item with eight or fewer digits (for example, using PICTURE S9(8 ) COMP for the data item). This will allow fullword arithmetic to be used during the calculations. Additionally, in some cases, using four or fewer digits for the data item may also offer some added reduction in CPU time since halfword arithmetic can be used.
Also check this link for a detailed explanation on COBOL for MVS & VM Performance Tuning
http://www-1.ibm.com/support/docview.wss?org=SW&doc=7001476&aid=1
Hope this helps...
Cheers
Kolusu _________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
 |
tattva Beginner
Joined: 02 Feb 2005 Posts: 97 Topics: 36
|
Posted: Wed Feb 02, 2005 9:23 am Post subject: |
|
|
Hi kolusu
Thanks for ur reply. But i have a couple of more ques here .
1) can i some how replace the exisiting code with Binary seacrh
2) is there any performace based differnce in searching a table by using
a) perform varying
b) search
as far as i know both a & b can be used to do a sequential search.correct me if i am wrong here!!!
TIA
------
Tattva |
|
Back to top |
|
 |
programmer1 Beginner
Joined: 18 Feb 2004 Posts: 138 Topics: 14
|
Posted: Wed Feb 02, 2005 9:50 am Post subject: |
|
|
I have observed SEARCH performing better than the Perform Varying loop. _________________ Regards,
Programmer |
|
Back to top |
|
 |
Bithead Advanced

Joined: 03 Jan 2003 Posts: 550 Topics: 23 Location: Michigan, USA
|
Posted: Wed Feb 02, 2005 9:58 am Post subject: |
|
|
SEARCH ALL provides the best performance. If there are duplicate CUST-NUM entries, try a SEARCH ALL then decrease the index until the CUST-NUM is less than the required value, then increase it by 1. |
|
Back to top |
|
 |
powerhawk Beginner

Joined: 08 Nov 2004 Posts: 28 Topics: 4 Location: Stockholm
|
Posted: Wed Feb 02, 2005 10:54 am Post subject: |
|
|
It's no big performance difference between SEARCH and SEARCH ALL if you have a small table (10-50 entries). If it's possible to put the most search values in the first entries you can get better performance with SEARCH than with SEARCH ALL. With bigger tables SEARCH ALL is much faster. If the table have 1000 entries SEARCH ALL is 83% faster in Enterprise Cobol.
To get best performance you should:
- Use SEARCH ALL
- Use OCCURS DEPENDING ON and declare the indexes with INDEXED BY.
- Of course sort the table, if you don't SEARCH ALL will fail. |
|
Back to top |
|
 |
powerhawk Beginner

Joined: 08 Nov 2004 Posts: 28 Topics: 4 Location: Stockholm
|
Posted: Wed Feb 02, 2005 10:59 am Post subject: |
|
|
I guess you can get a small speed improvement by moving CUST-NUM(index2) to a field declared outside the table, like W-CUST-NUM, and change the test in the SEARCH statement to: WHEN CUST-NUM(index1) = W-CUST-NUM... |
|
Back to top |
|
 |
powerhawk Beginner

Joined: 08 Nov 2004 Posts: 28 Topics: 4 Location: Stockholm
|
Posted: Thu Feb 03, 2005 2:28 am Post subject: |
|
|
Here is sample code: Code: |
05 FSALLMJ-WORK-LKFTABELL.
07 FSALLMJ-I-TOPLKF PIC S9(4) COMP.
07 FSALLMJ-I-MAXLKF PIC S9(4) COMP VALUE 500.
07 FSALLMJ-WORK-LKFENTRY OCCURS 1 TO 500 TIMES
DEPENDING ON FSALLMJ-I-TOPLKF
ASCENDING KEY FSALLMJ-WORK-LKF
INDEXED BY FSALLMJ-I-LKF FSALLMJ-I-LKF2.
09 FSALLMJ-WORK-LKF PIC X(6).
05 FSALLMJ-R-BYT PIC 9(9) COMP.
05 FSALLMJ-S-LKF PIC X(6).
*** *** FILL TABLE FROM LKF DATABASE
MOVE ZERO TO FSALLMJ-I-TOPLKF
PERFORM LK700-IO-GET-NEXT
PERFORM UNTIL NOT LK700-IO-OK
ADD 1 TO FSALLMJ-I-TOPLKF
MOVE LK700-LKFKOD TO FSALLMJ-WORK-LKF(FSALLMJ-I-TOPLKF)
PERFORM LK700-IO-GET-NEXT
END-PERFORM
*** *** SORTING LKF, COMPARE TWO ENTRIES. IF THEY ARE IN
*** *** WRONG ORDER CHANGE ORDER AND ADD THE CHANGE COUNTER.
*** *** WHEN CHANGE COUNTER IS ZERO AFTER A TABLE SCAN
*** *** THE SORT IS FINISHED.
MOVE 99 TO FSALLMJ-R-BYT
PERFORM UNTIL FSALLMJ-R-BYT = ZERO
MOVE ZERO TO FSALLMJ-R-BYT
SET FSALLMJ-I-LKF TO 1
SET FSALLMJ-I-LKF2 TO 2
PERFORM UNTIL FSALLMJ-I-LKF2 > FSALLMJ-I-TOPLKF
IF FSALLMJ-WORK-LKF(FSALLMJ-I-LKF) > FSALLMJ-WORK-LKF(FSALLMJ-I-LKF2)
MOVE FSALLMJ-WORK-LKF(FSALLMJ-I-LKF) TO FSALLMJ-S-LKF
MOVE FSALLMJ-WORK-LKF(FSALLMJ-I-LKF2) TO FSALLMJ-WORK-LKF(FSALLMJ-I-LKF)
MOVE FSALLMJ-S-LKF TO FSALLMJ-WORK-LKF(FSALLMJ-I-LKF2)
ADD 1 TO FSALLMJ-R-BYT
END-IF
SET FSALLMJ-I-LKF UP BY 1
SET FSALLMJ-I-LKF2 UP BY 1
END-PERFORM
END-PERFORM
*** *** SEARCH LKF TABLE
SET FSALLMJ-I-LKF TO 1
SEARCH ALL FSALLMJ-WORK-LKFENTRY
AT END
--- NOT FOUND HANDLER
WHEN FSALLMJ-WORK-LKF(FSALLMJ-I-LKF) = FSALLMJ-S-LKF
--- FOUND HANDLER
END-SEARCH | [/code] |
|
Back to top |
|
 |
tattva Beginner
Joined: 02 Feb 2005 Posts: 97 Topics: 36
|
Posted: Thu Feb 03, 2005 3:45 am Post subject: |
|
|
Hi Power,
thanks for the reply...
But if i have to replace it with ur logic.. then what about the third condition..
AND dia-num(index1)
>= '40000'
AND dia-num(index1)
<= '49999'
this cannot be taken care in Binary search .. right
Correct me if i am wrong here!!
Thnx
-------
Tattva |
|
Back to top |
|
 |
powerhawk Beginner

Joined: 08 Nov 2004 Posts: 28 Topics: 4 Location: Stockholm
|
Posted: Thu Feb 03, 2005 6:43 am Post subject: |
|
|
Sorry I don't know. I would fix a table sorted in ascending order on both fields and try. If it's possible you can also avoid to load all items with dia-num outside 4000-4999, or create a work table and move all items with dia-num from 4000 to 4999 from the original table to the work table. |
|
Back to top |
|
 |
Bithead Advanced

Joined: 03 Jan 2003 Posts: 550 Topics: 23 Location: Michigan, USA
|
Posted: Thu Feb 03, 2005 10:42 am Post subject: |
|
|
Tattva,
Please show all the code in the PERFORM? |
|
Back to top |
|
 |
slade Intermediate
Joined: 07 Feb 2003 Posts: 266 Topics: 1 Location: Edison, NJ USA
|
Posted: Thu Feb 03, 2005 8:56 pm Post subject: |
|
|
Another question is how are these 2 tables populated? Granted I don't know the full picture, but I get the feeling this might be better solved using a "file match" algorithm. _________________ Regards, Jack.
"A problem well stated is a problem half solved" -- Charles F. Kettering |
|
Back to top |
|
 |
tattva Beginner
Joined: 02 Feb 2005 Posts: 97 Topics: 36
|
Posted: Thu Feb 03, 2005 11:21 pm Post subject: |
|
|
hi guys,
Thanks for all your responses.. i was able to solve this.. But am facing some other Problem
Here's the problem
say am now doing a binary search on a table entries of which are loaded from a cursor..
1) should all the keys on which i am searching the table be present in the ORDER by clause ?
TIA
------
Tattva |
|
Back to top |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
|
|
Back to top |
|
 |
slade Intermediate
Joined: 07 Feb 2003 Posts: 266 Topics: 1 Location: Edison, NJ USA
|
Posted: Sat Feb 05, 2005 2:00 pm Post subject: |
|
|
Hi Tattva,
I'm not sure I understand the problem stmt you provided. You want to use SEARCH ALL using CUST-NUM as the search arg.
Then you compare CUST-NUM(IDX1) equal to CUST-NUM(IDX2). So far as I know you can't have dupe keys in a SEARCH ALL tbl. It'll work but the results are iffy. I'm assuming that CUST-NUM(IDX2) is referring to a different instance of the same data field in the same table as CUST-NUM(IDX1), since they both reference the same unqualified dataname. Is that correct?
BTW, how is the value of IDX2 determined?
All that aside, I guess you're trying to do something like this, as illustrated in Powerhawk's code (but that WHEN clause bothers me) : Code: |
SET IDX1 TO 1
SEARCH ALL YOUR-TBL-ENTRIES
AT END
--- do NOT in tbl stuff
WHEN CUST-NUM(IDX1) = CUST-NUM(IDX2)
IF dia-num(IDX1) >= '40000'
AND
dia-num(IDX1) <= '49999'
--- do found stuff
ELSE
--- do NUM out of range stuff
END-IF
END-SEARCH |
_________________ Regards, Jack.
"A problem well stated is a problem half solved" -- Charles F. Kettering |
|
Back to top |
|
 |
|
|