Consultor Eletrônico



Kbase P55318: What is the ETIME function?
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   22/04/2009
Status: Unverified

GOAL:

What is the ETIME function?

GOAL:

How do I use the ETIME function?

FACT(s) (Environment):

All Supported Operating Systems
Progress/OpenEdge Product Family

FIX:

You may be wondering (in fact, you should be wondering) how you can tell which of two constructs is faster in your situation, or how to measure the performance of a part of your application.
Progress has a profiling tool that can show you how much of your processing time is going to what routines, but there is also a much simpler way to do a test of a specific part of your code.
This is the ETIME function (for elapsed time). ETIME returns an integer value representing the number of milliseconds since the function was reset to zero. Because a millisecond is a substantial amount of time on a modern processor, you often have to repeat an action many times inside a loop to be able to measure accurately just what its cost is.

To reset the counter that ETIME uses, you invoke the function with an argument value of Yes or True. Otherwise you invoke it with no argument and no parentheses. If you forget to reset it to zero before you start, ETIME will return some enormous integer representing the number of milliseconds since your session started.

This example shows you whether it faster to use the FIND statement or a FOR FIRST block to find the (one) Order with a Customer Number of 24 and an Order Date of 1/31/98. If you look at the indexes for the Order table in the Data Dictionary, you see that there is an index on the Order Date field, and another index that has the CustNum field as its primary component, followed by the OrderNum field. The FOR FIRST construct takes advantage of both of these indexes to resolve the request in the most efficient way possible. The FIND statement can use only one of the indexes.

The code first resets ETIME, then does the same FIND in a loop 10000 times. It then saves the ETIME counter for this operation. Then it resets it again, does a FOR FIRST 10000 times, saves that value, and finally displays both values.

DEFINE VARIABLE iCount AS INTEGER NO-UNDO.
DEFINE VARIABLE iFindTime AS INTEGER NO-UNDO.
DEFINE VARIABLE iForTime AS INTEGER NO-UNDO.
ETIME(TRUE).
DO iCount = 1 TO 10000:
FIND Order WHERE CustNum = 24 AND OrderDate = 1/31/98.
END.
iFindTime = ETIME.
ETIME(TRUE).
DO iCount = 1 TO 10000:
FOR FIRST Order WHERE CustNum = 24 AND Orderdate = 1/31/98:
END.
END.
iForTime = ETIME.
MESSAGE "The FIND took " iFindTime " milliseconds " SKIP
"The FOR FIRST took " iForTime VIEW-AS ALERT-BOX.