View previous topic :: View next topic
|
Author |
Message |
avik
New User
Joined: 13 May 2008 Posts: 16 Location: kolkata
|
|
|
|
In some of COBOL codes,SEARCH verb was being used for all search purpose.But I have changed them to "SEARCH ALL" to process it faster wherever binary search was going on.
Now i am thinking of changing "SEARCH ALL" verb by an equivalent Assembler routine(for binary search).I think it will make that operation much more faster.I am a novice in Assembler coding.So can anyone of expert in Assembler help me out by provide an assembler routine for replacing those "SEARCH ALL" verbs?
Thanks in advance. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Do you understand the mechanics of a binary search? If not, learning how a binary search operates internally would be a good thing to do.
Keep in mind that when a binary search is specified, the actual search is done in assembler not cobol.
Also, keep in mind that the SEARCH statement supports condition-names and conditional expressoins that relate to components in the cobol code.
Once you are into the code and there are questons or problems, post what you have and your questions about it and someone here will be able to offer suggestions. |
|
Back to top |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
avik wrote: |
I am a novice in Assembler coding.So can anyone of expert in Assembler help me out by provide an assembler routine for replacing those "SEARCH ALL" verbs?
Thanks in advance. |
Considering all the options that are available in SEARCH ALL in COBOL I don't think this would be a good beginner's project. How will you handle different data formats (ie. comparing a PD field with a Binary, or a PIC x(5) with a PIC x(8) etc.)? |
|
Back to top |
|
|
avik
New User
Joined: 13 May 2008 Posts: 16 Location: kolkata
|
|
|
|
Refer to Dick's suggestion,For "SEARCH ALL" option what is the underlying Assembler code? Can you provide me that showing a very small example assuming some dummy conditions? Or is there any website for getting such code help for getting underlying code of "SEARCH ALL". |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
If you want to see the assembler for a SEARCH ALL you could look at the assembler generated by the compile of the cobol program containing the SEARCH ALL.
If you want to practice assembler and would like to implement a basic binary search, you may find this helpful:
en.wikipedia.org/wiki/Binary_search_algorithm
This routine would do nothing but search an ordered list - it would not replace SEARCH ALL.
As Craig mentioned, trying to write code that would be usable in place of SEARCH ALL is not a beginner task. |
|
Back to top |
|
|
avik
New User
Joined: 13 May 2008 Posts: 16 Location: kolkata
|
|
|
|
Thanks for your valuable suggestions.Actually I want to reduce the CPU execution time for binary search.So previously I have adopted COBOL best practice & converted "SEARCH" to "SEARCH ALL".As our cobol code consists a lots of use of binary search,So I thought of changing it to a Assembler code.
But I didn't think it will be so tough.So is it not possible of providing any generic Assembler routine by which I can replace my binary search to reduce my CPU execution time? or is there any other suggestion for improving binary search execution time?
Anyway I will go through the link provided by you & will will try to implement them.
Thanks... |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8697 Location: Dubuque, Iowa, USA
|
|
|
|
Quote: |
Actually I want to reduce the CPU execution time for binary search. |
Have you studied complexity of computer algorithms? Do you know what O(log n) refers to? For example,
Quote: |
Implementing Binary Search
Although the algorithm is simple to describe informally, it is tricky to produce a working binary search function. The first published binary search algorithm appeared in 1946, but the first correct published program appeared in 1962!
The difficulty is maintaining the following two invariants with each iteration:
* The key must always remain between the low and high indices.
* The low or high indice must advance each iteration.
The boundary cases are very tricky: zero elements left, one elements left, two elements left, and an even or odd number of elements! |
Your best bet is to reduce the number of searches being done. If you can't do that, your next best bet is to live with the current time. Any Assembler routine you create is (a) not likely to be right, and (b) not likely to be any faster than the existing COBOL code. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Another thing to remember is that we had need of a binary search long before SEARCH and SEARCH ALL were included in the cobol language. When we needed one, we wrote it "long-hand". IIRC it took less than 50 procedure division statements to code a binary search that performed well and worked correctly every time. There were also a handful of working storage variables to "keep track of where you were" and the array itself.
These hand coded binary searches quite out-performed a sequential search. When the SEARCH and SEARCH ALL were made available, they outran any of the "same" hand-coded routines.
Another aid to improving performance of this process (and others) may be found in the following. . .
At several sites i've discovered one "situation" that repeats over and over. The coders had written exactly to the specifications (i.e. when you get to this pont in the process, retrieve some value or verify the existence some "key") and searched as directed. What was not in the specs was that if the current value is the same as the previous value that came thru the code, there is no need to search again. |
|
Back to top |
|
|
|