PeopleCode | A system variable for the current time at the level of milliseconds.
<< Previous | Next >>
A. Difference between %Time and %PerfTime
You may already be familiar with the ‘%Time’ system variable, which displays the current time in terms of hours, minutes and seconds. For example:
MessageBox(0, " ", 0, 0, String(%Time));
But what if you’re faced with a requirement that demands more precision? What if, for instance, you wish to troubleshoot a slow running piece of code that requires you to get down into ‘machine time’? This is where ‘%PerfTime’ can come in useful:
MessageBox(0, " ", 0, 0, String(%PerfTime));
B. %PerfTime for Troubleshooting Performance
Now you can scatter some ‘%PerfTime’ statements throughout a block of slow-running code to get a better sense of where things are grinding to a halt. For example
MessageBox(0, " ", 0, 0, "CHECKOINT A: " | String(%PerfTime)); /* CODE BLOCK A */ MessageBox(0, " ", 0, 0, "CHECKOINT B: " | String(%PerfTime)); /* CODE BLOCK B */ MessageBox(0, " ", 0, 0, "CHECKOINT C: " | String(%PerfTime)); /* CODE BLOCK C */ MessageBox(0, " ", 0, 0, "CHECKOINT D: " | String(%PerfTime)); /* CODE BLOCK D */
C. MessageBox and Think-Time Processing
With the above example, you might be thinking: what about all the time taken to read each message and click on the ‘OK’ button? Doesn’t this contribute to the overall time required to execute the code?
This would certainly be a problem if we were using a ‘think-time’ function such as the older ‘WinMessage’ statement. A think-time function would have to wait for a certain event to take place before the code could continue to run. In this case, the event would be the user clicking an ‘OK’ button to dismiss a message.
However, because ‘MessageBox’ operates as a non-think-time function, it can be used to troubleshoot code performance without impacting on execution time. While each message is displayed in series, the rest of the code is executed as normal. Because the default ‘MessageBox’ statements are just messages – the first parameter of ‘0’ indicates a message with just an ‘OK’ button, thus requiring no additional input from the user – the code does not have to hang around and wait for a response. Processing continues as normal. As the developer, you can take as long as you need to note the contents of each message before moving on to the next, reassured that the reported times are accurate for the entire block.
D. Using %PerfTime for Random Numbers
‘%PerfTime’ is also useful for any requirement that asks you to generate a unique piece of text, such as an auto-generated run control ID:
&runControlID = "PROCESS_NAME_" | %PerfTime;
The addition of the ‘%PerfTime’ system variable works like a random number, giving you a piece of text that is unlikely to be duplicated. It’s also more useful than a random number as the time-stamp supplies a piece of information that could help in troubleshooting.
<< Previous | Next >>