About   -   Contact   -   Purchase   -   Search   -   What's New

Accurate Code Timings
When you want to find out how long a particular piece of code is taking to execute there are a few ways to go about it. You can use the new Profiling Option in PowerBuilder 6, but call me old fashioned I still like to use the simpler method described below.

PowerBuilder is a very rich product and quite often there are many ways of achieving the same thing (EG: GetItem, Dot notation) so when I'm making a decision about which way to perform a task I quite often what to know which way will perform the best.

To do this try to isolate the block of code into a separate object or window, then I setup a loop that executes the code many times in a loop, just executing the code once is not accurate enough, I normally execute it between 100 - 1000 times depending on the length of time required to perform the task.

One way to time the execution is to use a time variable and get the time either side of the loop, but when you are dealing with fast executing script where you want to be more accurate than a second you can make use of the CPU() command.

The Cpu returns the number of milliseconds since your PowerBuilder application started executing. So by grabbing this time either side of the loop you will get a more accurate reading of how long something takes. This is also very good when you cannot isolate a block of code to be run in a loop.


Long ll_StartCpu, ll_EndCpu, ll_I

ll_StartCpu = Cpu()
FOR ll_I = 1 TO 100
   your code
ll_EndCpu = Cpu()
MessageBox( "Code Took", ll_EndCpu - ll_StartCpu )


Top of Page

Legal Notice

Ken Howe 2011