Since p-code runs slower than machine language, you may want the speed-critical sections of your program to be compiled into machine language. If you use the /Oq option, you can specify what portions of your program are compiled into p-code with the optimize pragma for the q option. The pragma works on a function-by-function basis, and can only appear outside of function scope. For example,
#pragma optimize("q",on)
// Functions compiled into p-code
#pragma optimize("q",off)
// Functions compiled into machine code
These pragmas are ignored if the program is not compiled with the /Oq option.
The functions that are the best candidates for p-code compilation are those that interact directly with the user. The execution speed of such functions is limited by the speed of the user of the program, rather than the speed of the computer. Also suitable for p-code are rarely used operations and sections of code associated with error conditions. These functions can usually be converted into p-code without the program appearing noticeably slower to the user.
Summary: A profiler can help fine-tune p-code programs.
To further assist you in determining which functions should be compiled into
p-code and which should remain in machine language, you can use a “profiler.”
A profiler is a utility that monitors the execution of your program and lists how much time the program spent in each of its functions. This does not necessarily correspond to the frequency with which the functions are called; for example, a function may be called only once during a program, but it may take up most of the program's execution time.
You should run the profiler on your program before you compile any of it into p-code. The functions that are the most time-consuming should remain in machine language. The functions that take the least of your program's time can be converted into p-code to give you space savings with a minimal reduction in execution speed. As a final step in tuning, the profiler can be run on the mixed p-code and native program.