Take Away: To test the speed of your code, capture the time before and after your code executes and view the milliseconds between the two dates.
KB101163
Because there are many ways in ObjectPAL to accomplish a given task, you often need to test the speed of two routines. ObjectPAL offers, in the form of the time() method, an easy way to do this. To calculate the amount of time a scan loop takes on the CUSTOMER table, type in lines 3-19 into the ushbutton event of a button:
1: ;DATATYPE :: btnSpeed :: pushbutton 2: method ushbutton(var eventInfo Event) 3: var 4: tcCustomer Tcursor 5: tBeg, tEnd Time 6: nDifftime Number 7: endVar 8: 9: tcCustomer.open("CUSTOMER.DB") ;Open CUSTOMER.DB table. 10: 11: tBeg = time() ;Grab current time. 12: scan tcCustomer: 13: ;Nothing here. Just testing scan time. 14: endScan 15: tEnd = time() ;Grab current time. 16: 17: ;The following calculates the number of milliseconds that passed. 18: nDiffTime = number(tEnd) - number(tBeg) 19: nDiffTime.view("Milliseconds to scan Customer table") 20: endMethod
The preceding routine opens the CUSTOMER table, gets the current time, scans the CUSTOMER table, and then gets the current time again. Finally, it calculates the duration of the scan loop and displays it in milliseconds. Use the preceding technique whenever you need to know how fast a routine is in ObjectPAL-for example, when you discover two ways to accomplish the same task and need to determine which is faster.