Optimizing Scripts with the Script Profiler
- Updated2024-09-12
- 2 minute(s) read
(Scripts | Version 2015) > Optimizing Scripts with the Script Profiler
|
Optimizing Scripts with the Script Profiler |
Use the script profiler to measure and analyze the runtime of a script or the execution times of individual script statements. The script profiler is an analysis tool with which you detect time-consuming commands and statements and which helps you optimize your script.
This example shows you how to optimize scripts with the script profiler.
-
First open the following three script files by clicking the filename.
Profiler_Demo.vbs Script file Profiler_Demo_Optimized_1.vbs Script file Profiler_Demo_Optimized_2.vbs Script file -
Enable the script profiler with the button on the DIAdem SCRIPT toolbar or navigate to Script»Script-Profiler.
-
Start the script you want to check when the script profiler is enabled.
-
Click Analysis to open the script profiler result view in table form.
The three scripts demonstrate different optimization levels. The Profiler_Demo.vbs is not optimized. The script can be speeded up significantly with the next two optimization steps.
In the script profiler you can see that the Calculate command has the largest share of the total runtime of the script.
The Profiler_Demo_Optimized_1.vbs contains a first optimization step: The Calculate command has been replaced by two commands which calculate channels directly. The Calculate command is very flexible. However, this command is not as fast as commands dedicated to perform a certain task. The two commands ChnLinScale and ChnAdd, on the other hand, are dedicated to high-speed channel calculation. As the flexibility of the Calculate is not required in this script, you can significantly increase the execution speed through these specialized commands.
In the script profiler you can see that the ChannelGroups.Channels(x) and the Root.ChannelGroups(x) also take up a large share of the total runtime of the script.
The Profiler_Demo_Optimized_2.vbs contains a second optimization step: The fully qualified channel access Data.Root.ChannelGroups(1).Channels(2) was replaced by a channel object variable. For each fully qualified channel access, DIAdem must perform an object identification at each point (.). Particularly if you use these calls in loops, you can speed up the script by using an object variable.